From 9011c77c0eaac7200bc784be7dcffc9c56c8fc70 Mon Sep 17 00:00:00 2001 From: Fabien Costantini Date: Tue, 24 Apr 2012 01:12:54 +0000 Subject: Added range test in new fl_ascii_strcasecmp to avoid potential false positives. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@9390 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/flstring.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/flstring.c b/src/flstring.c index fcab1a765..25346b360 100644 --- a/src/flstring.c +++ b/src/flstring.c @@ -94,14 +94,18 @@ fl_strlcpy(char *dst, /* O - Destination string */ * 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; } -- cgit v1.2.3