From bd5d2162efae9913f2666c80bdf944a65ea95590 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 2 Sep 2015 04:44:53 +0200 Subject: fix more errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/string/strcmp.c | 7 +++++-- src/string/strdup.c | 1 + src/string/strstr.c | 12 +++++++++--- src/string/substring.h | 9 ++++++--- 4 files changed, 21 insertions(+), 8 deletions(-) (limited to 'src/string') diff --git a/src/string/strcmp.c b/src/string/strcmp.c index f626f91..56b4d1b 100644 --- a/src/string/strcmp.c +++ b/src/string/strcmp.c @@ -17,7 +17,7 @@ */ #include #include -#include +#include #include @@ -108,7 +108,7 @@ int strncmp(const char* a, const char* b, size_t length) int strncasecmp(const char* a, const char* b, size_t length) { int c1, c2; - for (; size--; a++, b++) + for (; length--; a++, b++) if (*a != *b) { c1 = isalpha(*a) ? tolower(*a) : (int)*a; @@ -116,6 +116,9 @@ int strncasecmp(const char* a, const char* b, size_t length) if ((c1 -= c2)) return c1; } + else if (!*a && !*b) return 0; + else if (!*a) return -1; + else if (!*b) return +1; return 0; } diff --git a/src/string/strdup.c b/src/string/strdup.c index c23548b..6a66c2c 100644 --- a/src/string/strdup.c +++ b/src/string/strdup.c @@ -16,6 +16,7 @@ * along with this program. If not, see . */ #include +#include diff --git a/src/string/strstr.c b/src/string/strstr.c index 68cc647..0c67153 100644 --- a/src/string/strstr.c +++ b/src/string/strstr.c @@ -16,7 +16,13 @@ * along with this program. If not, see . */ #include -#include +#include +#include +#include +#include + + +# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" @@ -143,7 +149,7 @@ void* memmem(const void* __haystack, size_t haystack_length, if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !memcmp(haystack, haystack_length, haystack_length) ? haystack : NULL; + return !memcmp(haystack, needle, haystack_length) ? haystack : NULL; #include "substring.h" } @@ -170,7 +176,7 @@ void* memcasemem(const void* __haystack, size_t haystack_length, if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !memcasecmp(haystack, haystack_length, haystack_length) ? haystack : NULL; + return !memcasecmp(haystack, needle, haystack_length) ? haystack : NULL; #define CASE #include "substring.h" #undef CASE diff --git a/src/string/substring.h b/src/string/substring.h index 10e4a7d..9d6dbfe 100644 --- a/src/string/substring.h +++ b/src/string/substring.h @@ -47,7 +47,7 @@ ssize_t hay, ned, skp; ned = 0, skp = next_map[0] = -1; - while (ned < needle_length) + while (ned < (ssize_t)needle_length) { while ((skp > -1) && !CHREQ(needle[ned], needle[skp])) skp = next_map[skp]; @@ -56,15 +56,18 @@ } hay = ned = 0; - while (hay < haystack_length) + while (hay < (ssize_t)haystack_length) { while ((ned > -1) && !CHREQ(haystack[hay], needle[ned])) ned = next_map[ned]; hay++, ned++; - if (ned >= needle_length) + if (ned >= (ssize_t)needle_length) return needle + (hay - ned); } return NULL; } + +#undef CHREQ + -- cgit v1.2.3-70-g09d2