charset: fix str[n]casecmp_m() by comparing lower case values
authorStefan Metzmacher <metze@samba.org>
Wed, 6 Sep 2017 07:47:20 +0000 (09:47 +0200)
committerRalph Boehme <slow@samba.org>
Fri, 15 Sep 2017 00:23:29 +0000 (02:23 +0200)
The commits c615ebed6e3d273a682806b952d543e834e5630d^..f19ab5d334e3fb15761fb009e5de876dfc6ea785
replaced Str[n]CaseCmp() by str[n]casecmp_m().

The logic we had in str[n]casecmp_w() used to compare
the upper cased as well as the lower cased versions of the
characters and returned the difference between the lower cased versions.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13018

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Fri Sep 15 02:23:29 CEST 2017 on sn-devel-144

lib/util/charset/util_str.c
selftest/knownfail.d/strcasecmp [deleted file]

index 550fba3ed64466a8ec88c64c8186436fefd7a87f..6feed1742ac48b3177ee3d87596eac5007fca42e 100644 (file)
@@ -36,6 +36,8 @@ _PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
                                 const char *s1, const char *s2)
 {
        codepoint_t c1=0, c2=0;
+       codepoint_t u1=0, u2=0;
+       codepoint_t l1=0, l2=0;
        size_t size1, size2;
 
        /* handle null ptr comparisons to simplify the use in qsort */
@@ -59,9 +61,19 @@ _PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
                        continue;
                }
 
-               if (toupper_m(c1) != toupper_m(c2)) {
-                       return c1 - c2;
+               u1 = toupper_m(c1);
+               u2 = toupper_m(c2);
+               if (u1 == u2) {
+                       continue;
                }
+
+               l1 = tolower_m(c1);
+               l2 = tolower_m(c2);
+               if (l1 == l2) {
+                       continue;
+               }
+
+               return l1 - l2;
        }
 
        return *s1 - *s2;
@@ -83,6 +95,8 @@ _PUBLIC_ int strncasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
                                  const char *s1, const char *s2, size_t n)
 {
        codepoint_t c1=0, c2=0;
+       codepoint_t u1=0, u2=0;
+       codepoint_t l1=0, l2=0;
        size_t size1, size2;
 
        /* handle null ptr comparisons to simplify the use in qsort */
@@ -123,9 +137,19 @@ _PUBLIC_ int strncasecmp_m_handle(struct smb_iconv_handle *iconv_handle,
                        continue;
                }
 
-               if (toupper_m(c1) != toupper_m(c2)) {
-                       return c1 - c2;
+               u1 = toupper_m(c1);
+               u2 = toupper_m(c2);
+               if (u1 == u2) {
+                       continue;
                }
+
+               l1 = tolower_m(c1);
+               l2 = tolower_m(c2);
+               if (l1 == l2) {
+                       continue;
+               }
+
+               return l1 - l2;
        }
 
        if (n == 0) {
diff --git a/selftest/knownfail.d/strcasecmp b/selftest/knownfail.d/strcasecmp
deleted file mode 100644 (file)
index 23d755a..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-^samba4.local.charset.strcasecmp_m
-^samba4.local.charset.strncasecmp_m