From c722a590d08506f29ddb70c1c57c511a836efb7a Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 10 Mar 2021 14:26:46 -0500 Subject: Add more string test cases. This adds test cases for the rest of our ASCII string functions. While doing so, it fixes two minor bugs: - strcasecmp() now handles utf8 correctly - strncpy() no longer does the stpncpy() behavior of clearing leftover buffer Signed-off-by: Peter Jones --- lib/string.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib/string.c') diff --git a/lib/string.c b/lib/string.c index 3dc6f1cd..37eabe8c 100644 --- a/lib/string.c +++ b/lib/string.c @@ -13,6 +13,7 @@ #define strcasecmp shim_strcasecmp #define strrchr shim_strrchr #define strlen shim_strlen +#define strnlen shim_strnlen #define strcpy shim_strcpy #define strncpy shim_strncpy #define strdup shim_strdup @@ -93,7 +94,7 @@ strncasecmp(const char *s1p, const char *s2p, size_t n) int strcasecmp(const char *str1, const char *str2) { - char c1, c2; + uint8_t c1, c2; c1 = toupper(*str1); c2 = toupper(*str2); @@ -155,7 +156,7 @@ strncpy(char *dest, const char *src, size_t n) for (i = 0; i < n && src[i] != '\0'; i++) dest[i] = src[i]; - for (; i < n; i++) + if (i < n) dest[i] = '\0'; return dest; -- cgit v1.2.3