diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-05-29 16:07:51 -0400 |
---|---|---|
committer | Edward Thomson <ethomson@microsoft.com> | 2015-05-29 16:07:51 -0400 |
commit | 006548da91bfe05375ae0e786c6c13e9bad85a40 (patch) | |
tree | 2b7ad496d1768cd7192d39d6d89f85d5a6ec5e69 /src/util.c | |
parent | c7f94123569e8fe00ffb3a35e6a12b6ebe9320ec (diff) | |
download | libgit2-006548da91bfe05375ae0e786c6c13e9bad85a40.tar.gz |
git__strcasecmp: treat input bytes as unsigned
Treat input bytes as unsigned before doing arithmetic on them,
lest we look at some non-ASCII byte (like a UTF-8 character) as a
negative value and perform the comparison incorrectly.
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c index 6bb7d03ee..b8d6cf58c 100644 --- a/src/util.c +++ b/src/util.c @@ -173,7 +173,7 @@ int git__strcasecmp(const char *a, const char *b) { while (*a && *b && tolower(*a) == tolower(*b)) ++a, ++b; - return (tolower(*a) - tolower(*b)); + return ((unsigned char)tolower(*a) - (unsigned char)tolower(*b)); } int git__strcasesort_cmp(const char *a, const char *b) @@ -193,7 +193,7 @@ int git__strcasesort_cmp(const char *a, const char *b) } if (*a || *b) - return tolower(*a) - tolower(*b); + return (unsigned char)tolower(*a) - (unsigned char)tolower(*b); return cmp; } |