diff options
author | Liu Tao <liutao1980@gmail.com> | 2010-09-08 10:27:13 +0000 |
---|---|---|
committer | Patrick Georgi <patrick.georgi@coresystems.de> | 2010-09-08 10:27:13 +0000 |
commit | e914b501d25fe5af769a3753a56f7b01fb08ab2c (patch) | |
tree | 00a182b3262c1eb5f30002495bb4884f4a0d03e7 /payloads/libpayload | |
parent | fe09fd1dacd76badd7a2adf8c8933d927f4bce93 (diff) | |
download | coreboot-e914b501d25fe5af769a3753a56f7b01fb08ab2c.tar.xz |
Changes to str*cmp functions. Fixes a couple more corner cases.
Signed-off-by: Liu Tao <liutao1980@gmail.com>
Acked-by: Patrick Georgi <patrick.georgi@coresystems.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5785 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads/libpayload')
-rw-r--r-- | payloads/libpayload/libc/string.c | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c index 7bf19ace37..ce5767e4b0 100644 --- a/payloads/libpayload/libc/string.c +++ b/payloads/libpayload/libc/string.c @@ -89,14 +89,15 @@ size_t strlen(const char *str) */ 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 strcasecmp(const char *s1, const char *s2) */ 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 strncasecmp(const char *s1, const char *s2, size_t maxlen) */ 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 strcmp(const char *s1, const char *s2) */ 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; } /** |