Patchwork libpayload string.c fix

login
register
about
Submitter Liu Tao
Date 2010-09-08 01:40:05
Message ID <AANLkTimYZL6oyihKdbOtL6VB+MVBj4hH=D=-_xUGZeJy@mail.gmail.com>
Download mbox | patch
Permalink /patch/1887/
State Accepted
Headers show

Comments

Liu Tao - 2010-09-08 01:40:05
Hello,

the patch fixes strcmp()/strncmp()/strcasecmp()/strncasecmp() in
libpayload string.c

Signed-off-by: Liu Tao <liutao1980@gmail.com>
Patrick Georgi - 2010-09-08 10:27:38
Am 08.09.2010 03:40, schrieb Liu Tao:
> Signed-off-by: Liu Tao <liutao1980@gmail.com>
Thank you, committed in r5785

Regards,
Patrick

Patch

Index: payloads/libpayload/libc/string.c
===================================================================
--- payloads/libpayload/libc/string.c	(revision 5780)
+++ payloads/libpayload/libc/string.c	(working copy)
@@ -89,14 +89,15 @@ 
  */
 int strcasecmp(const char *s1, const char *s2)
 {
-	int i;
+	int i, res;
 
-	for (i = 0; s1[i] != '\0'; i++) {
-		if (tolower(s1[i]) != tolower(s2[i]))
-			return s1[i] - s2[i];
+	for (i = 0; 1; i++) {
+		res = tolower(s1[i]) - tolower(s2[i]);
+		if (res || (s1[i] == '\0'))
+			break;
 	}
 
-	return 0;
+	return res;
 }
 
 /**
@@ -109,14 +110,16 @@ 
  */
 int strncasecmp(const char *s1, const char *s2, size_t maxlen)
 {
-	int i;
+	int i, res;
 
+	res = 0;
 	for (i = 0; i < maxlen; i++) {
-		if (tolower(s1[i]) != tolower(s2[i]))
-			return s1[i] - s2[i];
+		res = tolower(s1[i]) - tolower(s2[i]);
+		if (res || (s1[i] == '\0'))
+			break;
 	}
 
-	return s1[i] - s2[i];
+	return res;
 }
 
 /**
@@ -130,14 +133,15 @@ 
  */
 int strcmp(const char *s1, const char *s2)
 {
-	int i;
+	int i, res;
 
-	for (i = 0; s1[i] != '\0'; i++) {
-		if (s1[i] != s2[i])
-			return s1[i] - s2[i];
+	for (i = 0; 1; i++) {
+		res = s1[i] - s2[i];
+		if (res || (s1[i] == '\0'))
+			break;
 	}
 
-	return s1[i] - s2[i];
+	return res;
 }
 
 /**
@@ -150,14 +154,16 @@ 
  */
 int strncmp(const char *s1, const char *s2, size_t maxlen)
 {
-	int i;
+	int i, res;
 
+	res = 0;
 	for (i = 0; i < maxlen; i++) {
-		if (s1[i] != s2[i])
-			return s1[i] - s2[i];
+		res = s1[i] - s2[i];
+		if (res || (s1[i] == '\0'))
+			break;
 	}
 
-	return 0;
+	return res;
 }
 
 /**