From 521eadd0c7526cbe88c60e0bd94a5f93b2c348ef Mon Sep 17 00:00:00 2001 From: Michael Elkins Date: Sat, 1 Dec 2012 14:31:42 -0800 Subject: [PATCH] make ascii_strcasecmp properly handle unequal length strings with the same prefix closes #3601 --- ascii.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ascii.c b/ascii.c index 1076f8f2..45f7e5d0 100644 --- 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; -- 2.40.0