p_clear should not be used with sizeof but *countof*
authorPierre Habouzit <madcoder@debian.org>
Thu, 9 Nov 2006 01:43:49 +0000 (02:43 +0100)
committerPierre Habouzit <madcoder@debian.org>
Thu, 9 Nov 2006 01:43:49 +0000 (02:43 +0100)
the p-clear(Matches) erased too much memory.
thanks valgrind

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
alias.c
init.c
lib-crypt/pgp.c
lib-crypt/smime.c
lib-lib/file.c
main.c

diff --git a/alias.c b/alias.c
index f0f129d..028f9ba 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -405,7 +405,7 @@ int mutt_alias_complete (char *s, size_t buflen)
 #define min(a,b)        ((a<b)?a:b)
 
   if (s[0] != 0) {              /* avoid empty string as strstr argument */
-    p_clear(bestname, sizeof(bestname));
+    p_clear(bestname, countof(bestname));
 
     while (a) {
       if (a->name && strstr (a->name, s) == a->name) {
diff --git a/init.c b/init.c
index 6545888..7ff48e9 100644 (file)
--- a/init.c
+++ b/init.c
@@ -2233,7 +2233,7 @@ char User_typed[LONG_STRING] = { 0 };
 
 int Num_matched = 0;            /* Number of matches for completion */
 char Completed[STRING] = { 0 }; /* completed string (command or variable) */
-const char *Matches[MAX (NUMVARS, NUMCOMMANDS) + 1];  /* all the matches + User_typed */
+char *Matches[MAX (NUMVARS, NUMCOMMANDS) + 1];  /* all the matches + User_typed */
 
 /* helper function for completion.  Changes the dest buffer if
    necessary/possible to aid completion.
@@ -2275,8 +2275,8 @@ int mutt_command_complete (char *buffer, size_t len, int pos, int numtabs)
     if (numtabs == 1) {
       Num_matched = 0;
       m_strcpy(User_typed, sizeof(User_typed), pt);
-      p_clear(Matches, sizeof(Matches));
-      p_clear(Completed, sizeof(Completed));
+      p_clear(Matches, countof(Matches));
+      p_clear(Completed, countof(Completed));
       for (num = 0; Commands[num].name; num++)
         candidate (Completed, User_typed, Commands[num].name,
                    sizeof(Completed));
@@ -2324,8 +2324,8 @@ int mutt_command_complete (char *buffer, size_t len, int pos, int numtabs)
     if (numtabs == 1) {
       Num_matched = 0;
       m_strcpy(User_typed, sizeof(User_typed), pt);
-      p_clear(Matches, sizeof(Matches));
-      p_clear(Completed, sizeof(Completed));
+      p_clear(Matches, countof(Matches));
+      p_clear(Completed, countof(Completed));
       for (num = 0; MuttVars[num].option; num++)
         candidate(Completed, User_typed, MuttVars[num].option,
                   sizeof(Completed));
@@ -2362,8 +2362,8 @@ int mutt_command_complete (char *buffer, size_t len, int pos, int numtabs)
     if (numtabs == 1) {
       Num_matched = 0;
       m_strcpy(User_typed, sizeof(User_typed), pt);
-      p_clear(Matches, sizeof(Matches));
-      p_clear(Completed, sizeof(Completed));
+      p_clear(Matches, countof(Matches));
+      p_clear(Completed, countof(Completed));
       for (num = 0; menu[num].name; num++)
         candidate (Completed, User_typed, menu[num].name, sizeof(Completed));
       /* try the generic menu */
index 1c9e4bc..038ba81 100644 (file)
@@ -69,7 +69,7 @@ time_t PgpExptime = 0;          /* when does the cached passphrase expire? */
 
 void pgp_void_passphrase (void)
 {
-  p_clear(PgpPass, sizeof(PgpPass));
+  p_clear(PgpPass, countof(PgpPass));
   PgpExptime = 0;
 }
 
index d520287..fe6b6cf 100644 (file)
@@ -102,7 +102,7 @@ static char SmimeIntermediateToUse[_POSIX_PATH_MAX];
 
 void smime_void_passphrase (void)
 {
-  p_clear(SmimePass, sizeof(SmimePass));
+  p_clear(SmimePass, countof(SmimePass));
   SmimeExptime = 0;
 }
 
index 36d34a3..7809db3 100644 (file)
@@ -208,7 +208,7 @@ void mutt_unlink(const char *s)
             char buf[BUFSIZ];
             unlink(s);
 
-            p_clear(buf, sizeof(buf));
+            p_clear(buf, countof(buf));
             while (sb.st_size > 0) {
                 fwrite(buf, 1, MIN(ssizeof(buf), sb.st_size), f);
                 sb.st_size -= MIN(ssizeof(buf), sb.st_size);
diff --git a/main.c b/main.c
index 84c320e..4ea396f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -546,8 +546,8 @@ int main (int argc, char **argv)
   SRAND (time (NULL));
   umask (077);
 
-  p_clear(Options, sizeof(Options));
-  p_clear(QuadOptions, sizeof(QuadOptions));
+  p_clear(Options, countof(Options));
+  p_clear(QuadOptions, countof(QuadOptions));
 
 #ifdef USE_NNTP
   while ((i =