Commit 853488eed45f2f620fdfc4879827df02bc11553e

Philip Kelley 2013-01-03T08:45:09

Fix git__strncasecmp

diff --git a/src/util.c b/src/util.c
index 059e55d..ba849aa 100644
--- a/src/util.c
+++ b/src/util.c
@@ -199,17 +199,15 @@ int git__strncmp(const char *a, const char *b, size_t sz)
 
 int git__strncasecmp(const char *a, const char *b, size_t sz)
 {
-	int al = 0, bl = 0;
+	int al, bl;
 
-	while (sz && *a && *b) {
+	do {
 		al = (unsigned char)tolower(*a);
 		bl = (unsigned char)tolower(*b);
-		if (al != bl)
-			break;
-		--sz, ++a, ++b;
-	}
+		++a, ++b;
+	} while (--sz && al && al == bl);
 
-	return !sz ? 0 : al - bl;
+	return al - bl;
 }
 
 void git__strntolower(char *str, size_t len)