Mercurial > hg > th-libs
changeset 262:e459a28ee1be
Found some nasty bugs hiding in th_str{n}casecmp() functions via unit tests. Fixed.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 17 Feb 2016 13:27:23 +0200 |
parents | f1decaee6157 |
children | 423771158575 |
files | th_string.c |
diffstat | 1 files changed, 10 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/th_string.c Wed Feb 17 12:59:55 2016 +0200 +++ b/th_string.c Wed Feb 17 13:27:23 2016 +0200 @@ -535,13 +535,16 @@ if (haystack == needle) return 0; - while (*s1 && *s2 && th_tolower(*s1) == th_tolower(*s2)) + while (*s1 && *s2) { + int k = th_tolower(*s1) - th_tolower(*s2); + if (k != 0) + return k; s1++; s2++; } - return th_tolower(*s1) - th_tolower(*s2); + return 0; } @@ -554,14 +557,17 @@ if (haystack == needle) return 0; - while (n > 0 && *s1 && *s2 && th_tolower(*s1) == th_tolower(*s2)) + while (n > 0 && *s1 && *s2) { + int k = th_tolower(*s1) - th_tolower(*s2); + if (k != 0) + return k; s1++; s2++; n--; } - return n > 0 ? (th_tolower(*s1) - th_tolower(*s2)) : 0; + return 0; }