r17980: handle NULL arguments without crashing in strcasecmp_m() and
authorAndrew Tridgell <tridge@samba.org>
Fri, 1 Sep 2006 04:23:24 +0000 (04:23 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:16:59 +0000 (14:16 -0500)
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

index 80c1d3b125b9c6e2d487ede8bd5ca6b74ab1e0b9..e6d929b4e585c40bf1062f88667d90f2d7578fd0 100644 (file)
@@ -123,6 +123,11 @@ _PUBLIC_ int strcasecmp_m(const char *s1, const char *s2)
        codepoint_t c1=0, c2=0;
        size_t size1, size2;
 
        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);
        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;
 
        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--;
 
        while (*s1 && *s2 && n) {
                n--;