]> granicus.if.org Git - mutt/commitdiff
make ascii_strcasecmp properly handle unequal length strings with the same prefix
authorMichael Elkins <me@sigpipe.org>
Sat, 1 Dec 2012 22:31:42 +0000 (14:31 -0800)
committerMichael Elkins <me@sigpipe.org>
Sat, 1 Dec 2012 22:31:42 +0000 (14:31 -0800)
closes #3601

ascii.c

diff --git a/ascii.c b/ascii.c
index 1076f8f2f724c8b7b55f8fc2ad6b928317a06647..45f7e5d09410071c270ea151417b5e4cd6f322f2 100644 (file)
--- a/ascii.c
+++ b/ascii.c
@@ -71,10 +71,15 @@ int ascii_strcasecmp (const char *a, const char *b)
   if (b == NULL && a)
     return 1;
   
-  for (; *a || *b; a++, b++)
+  for (;; a++, b++)
   {
     if ((i = ascii_tolower (*a) - ascii_tolower (*b)))
       return i;
+    /* test for NUL here rather that in the for loop in order to detect unqual
+     * length strings (see http://dev.mutt.org/trac/ticket/3601)
+     */
+    if (!*a)
+      break;
   }
   
   return 0;