Fixed bug in SDL_strcasecmp() with strings of different sizes
authorSam Lantinga <slouken@libsdl.org>
Sat, 22 Dec 2012 16:52:33 -0800
changeset 6766 2b8a507c278b
parent 6765 5448f332bfe6
child 6767 0d46fb7f06d4
Fixed bug in SDL_strcasecmp() with strings of different sizes
src/stdlib/SDL_string.c
--- a/src/stdlib/SDL_string.c	Sat Dec 22 16:52:00 2012 -0800
+++ b/src/stdlib/SDL_string.c	Sat Dec 22 16:52:33 2012 -0800
@@ -858,9 +858,13 @@
         ++str2;
         --maxlen;
     }
-    a = SDL_tolower((unsigned char) *str1);
-    b = SDL_tolower((unsigned char) *str2);
-    return (int) ((unsigned char) a - (unsigned char) b);
+    if (maxlen == 0) {
+        return 0;
+    } else {
+        a = SDL_tolower((unsigned char) *str1);
+        b = SDL_tolower((unsigned char) *str2);
+        return (int) ((unsigned char) a - (unsigned char) b);
+    }
 }
 #endif