summaryrefslogtreecommitdiff
path: root/libc/string/string.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-11-22 21:18:34 +0000
committerEric Andersen <andersen@codepoet.org>2000-11-22 21:18:34 +0000
commitc25724dc73a4a81cd610508da9e63cf4304dea25 (patch)
treebd4cd5f6e7eac5df4532084e11be5e93f4d8fdaf /libc/string/string.c
parentfe338b330e308bc69241900b1c518f1d752e6496 (diff)
Fix a bug in memcmp -- don't terminate the compare on a NULL, keep
comparing up to n bytes, till the are found to be either the same or differernt.
Diffstat (limited to 'libc/string/string.c')
-rw-r--r--libc/string/string.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/libc/string/string.c b/libc/string/string.c
index eb5c17709..fdf848125 100644
--- a/libc/string/string.c
+++ b/libc/string/string.c
@@ -2,6 +2,9 @@
/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
* This file is part of the Linux-8086 C library and is distributed
* under the GNU Library General Public License.
+ *
+ * Many of the functions in this file have been rewritten for correctness
+ * (but not necessarily speed) by Erik Andersen <andersee@debian.org>
*/
#include <string.h>
@@ -263,21 +266,16 @@ void *memchr(const void *str, int c, size_t len)
#ifdef L_memcmp
int memcmp(const void *s1, const void *s2, size_t len)
{
- unsigned register char c1 = '\0';
- unsigned register char c2 = '\0';
-
- register char *str1 = (char *) s1;
- register char *str2 = (char *) s2;
+ unsigned char *c1 = (unsigned char *)s1;
+ unsigned char *c2 = (unsigned char *)s2;
- while (len > 0) {
- c1 = (unsigned char) *str1++;
- c2 = (unsigned char) *str2++;
- if (c1 == '\0' || c1 != c2)
- return c1 - c2;
- len--;
+ while (len--) {
+ if (*c1 != *c2)
+ return *c1 - *c2;
+ c1++;
+ c2++;
}
-
- return c1 - c2;
+ return 0;
}
#endif