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/wchar/wcscmp.c | 7 +++++-- src/wchar/wcsstr.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/wchar') diff --git a/src/wchar/wcscmp.c b/src/wchar/wcscmp.c index c9d1180..7539458 100644 --- a/src/wchar/wcscmp.c +++ b/src/wchar/wcscmp.c @@ -16,7 +16,7 @@ * along with this program. If not, see . */ #include -#include +#include #include @@ -111,7 +111,7 @@ int wcsncmp(const wchar_t* a, const wchar_t* b, size_t length) int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t length) { wchar_t c1, c2; - for (; size--; a++, b++) + for (; length--; a++, b++) if (*a != *b) { c1 = iswalpha(*a) ? towlower(*a) : *a; @@ -119,6 +119,9 @@ int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t length) if (c1 < c2) return -1; if (c1 > c2) return +1; } + else if (!*a && !*b) return 0; + else if (!*a) return -1; + else if (!*b) return +1; return 0; } diff --git a/src/wchar/wcsstr.c b/src/wchar/wcsstr.c index 0ae7b71..1a4786e 100644 --- a/src/wchar/wcsstr.c +++ b/src/wchar/wcsstr.c @@ -16,11 +16,17 @@ * along with this program. If not, see . */ #include -#include +#include +#include +#include +#include #define WIDE +# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" + + /** * This function is identical to `wcsstr`. @@ -155,7 +161,7 @@ wchar_t* wmemmem(const wchar_t* haystack, size_t haystack_length, if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !wmemcmp(haystack, haystack_length, haystack_length) ? haystack : NULL; + return !wmemcmp(haystack, needle, haystack_length) ? haystack : NULL; #include "../string/substring.h" } @@ -180,7 +186,7 @@ wchar_t* wmemcasemem(const wchar_t* haystack, size_t haystack_length, if (haystack_length < needle_length) return NULL; if (haystack_length == needle_length) - return !wmemcasecmp(haystack, haystack_length, haystack_length) ? haystack : NULL; + return !wmemcasecmp(haystack, needle, haystack_length) ? haystack : NULL; #define CASE #include "../string/substring.h" #undef CASE -- cgit v1.2.3-70-g09d2