From: Pierre Habouzit Date: Thu, 9 Nov 2006 01:43:49 +0000 (+0100) Subject: p_clear should not be used with sizeof but *countof* X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=1ffe18af5bf2fda6f7dc86c514b56c6a82ec3040;p=apps%2Fmadmutt.git p_clear should not be used with sizeof but *countof* the p-clear(Matches) erased too much memory. thanks valgrind Signed-off-by: Pierre Habouzit --- diff --git a/alias.c b/alias.c index f0f129d..028f9ba 100644 --- a/alias.c +++ b/alias.c @@ -405,7 +405,7 @@ int mutt_alias_complete (char *s, size_t buflen) #define min(a,b) ((aname && strstr (a->name, s) == a->name) { diff --git a/init.c b/init.c index 6545888..7ff48e9 100644 --- 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 */ diff --git a/lib-crypt/pgp.c b/lib-crypt/pgp.c index 1c9e4bc..038ba81 100644 --- a/lib-crypt/pgp.c +++ b/lib-crypt/pgp.c @@ -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; } diff --git a/lib-crypt/smime.c b/lib-crypt/smime.c index d520287..fe6b6cf 100644 --- a/lib-crypt/smime.c +++ b/lib-crypt/smime.c @@ -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; } diff --git a/lib-lib/file.c b/lib-lib/file.c index 36d34a3..7809db3 100644 --- a/lib-lib/file.c +++ b/lib-lib/file.c @@ -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 --- 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 =