From e424b054d1c9c4c6e1adb4ae7da8232766282c33 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 1 Sep 2006 04:23:24 +0000 Subject: r17980: handle NULL arguments without crashing in strcasecmp_m() and strncasecmp_m(). This makes the use of these functions in sorting routines with RPC replies sane (This used to be commit 93413f84502ff308e88947b9d3bdc9d219478935) --- source4/lib/charset/util_unistr.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source4') diff --git a/source4/lib/charset/util_unistr.c b/source4/lib/charset/util_unistr.c index 80c1d3b125..e6d929b4e5 100644 --- a/source4/lib/charset/util_unistr.c +++ b/source4/lib/charset/util_unistr.c @@ -123,6 +123,11 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2) codepoint_t c1=0, c2=0; size_t size1, size2; + /* handle null ptr comparisons to simplify the use in qsort */ + if (s1 == s2) return 0; + if (s1 == NULL) return -1; + if (s2 == NULL) return 1; + while (*s1 && *s2) { c1 = next_codepoint(s1, &size1); c2 = next_codepoint(s2, &size2); @@ -202,6 +207,11 @@ _PUBLIC_ int strncasecmp_m(const char *s1, const char *s2, size_t n) codepoint_t c1=0, c2=0; size_t size1, size2; + /* handle null ptr comparisons to simplify the use in qsort */ + if (s1 == s2) return 0; + if (s1 == NULL) return -1; + if (s2 == NULL) return 1; + while (*s1 && *s2 && n) { n--; -- cgit