summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJoseph Bisch <joseph.bisch@gmail.com>2017-09-21 20:58:55 -0400
committerTingPing <tingping@tingping.se>2017-09-21 21:34:14 -0400
commit0c494a9c24c431f39b24abb5d90b6221d554a688 (patch)
treed86790be5837e21b18659e4dc44ffde66900c529
parent053003f490aaf876c01fa0fa8c64674436aee048 (diff)
Fix rfc_ncasecmp handling of n reaching 0
If n becomes 0 at the same time that the end of either s1 or s2 are
reached, the next iteration of the while loop wouldn't happen, so we
wouldn't correctly return 0.
-rw-r--r--src/common/util.c7
1 files changed, 2 insertions, 5 deletions
diff --git a/src/common/util.c b/src/common/util.c
index e61298ab..5b5fb23f 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1040,11 +1040,8 @@ rfc_ncasecmp (char *s1, char *s2, int n)
 {
 	int c1, c2;
 
-	while (*s1 && *s2)
+	while (*s1 && *s2 && n > 0)
 	{
-		if (n == 0)
-			return 0;
-
 		c1 = (int)rfc_tolower (*s1);
 		c2 = (int)rfc_tolower (*s2);
 		if (c1 != c2)
@@ -1055,7 +1052,7 @@ rfc_ncasecmp (char *s1, char *s2, int n)
 	}
 	c1 = (int)rfc_tolower (*s1);
 	c2 = (int)rfc_tolower (*s2);
-	return (c1 - c2);
+	return (n == 0) ? 0 : (c1 - c2);
 }
 
 const unsigned char rfc_tolowertab[] =