Author: fabien
Date: 2012-04-23 18:12:54 -0700 (Mon, 23 Apr 2012)
New Revision: 9390
Log:
Added range test in new fl_ascii_strcasecmp to avoid potential false positives.

Modified:
   branches/branch-1.3/src/flstring.c

Modified: branches/branch-1.3/src/flstring.c
===================================================================
--- branches/branch-1.3/src/flstring.c  2012-04-23 20:15:43 UTC (rev 9389)
+++ branches/branch-1.3/src/flstring.c  2012-04-24 01:12:54 UTC (rev 9390)
@@ -94,14 +94,18 @@
 * locale independent ascii oriented case cmp
 * returns 0 if string successfully compare, non zero otherwise
 */
+#define C_RANGE(c,l,r) ( (c) >= (l) && (c) <= (r) )
+
 int fl_ascii_strcasecmp(const char *s, const char *t) {
        if (!s || !t) return (s!=t);
        if (strlen(s) != strlen(t)) return -1;
        for(;*s; s++,t++) {
-               if ( *s != *t) {
-                       if (*s<*t && (*s+0x20)!=*t ) return -1;
-                       if (*s>*t && *s!=(*t+0x20) ) return +1;
-               }
+         if (*s == *t) continue;
+         if (*s < *t) {
+           if ( (*s+0x20)!=*t || !C_RANGE(*s,'A','Z') ) return -1;
+         } else { // *s > *t
+           if ( (*s-0x20)!=*t || !C_RANGE(*s,'a','z') ) return +1;
+         }
        }
        return 0;
 }

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to