diff options
author | Volker Lendecke <vl@samba.org> | 2014-08-05 09:21:07 +0000 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2014-08-06 01:05:14 +0200 |
commit | 64271c493df66f1dc67fae7fa14ec75f49db65af (patch) | |
tree | f397443d0efd545e480ad58c9e1c6c7df1959dd9 /lib | |
parent | ca1617121a2a6418c2e3ab7a7ce92ddaa1368ce2 (diff) | |
download | samba-64271c493df66f1dc67fae7fa14ec75f49db65af.tar.gz |
lib: strings: Simplify strcasecmp
This makes us fallback to strcasecmp early if any INVALID_CODEPOINT
appears. Without this patch we just continue to compare if both strings
happen to have an INVALID_CODEPOINT in the same spot.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/util/charset/util_str.c | 48 |
1 files changed, 13 insertions, 35 deletions
diff --git a/lib/util/charset/util_str.c b/lib/util/charset/util_str.c index f62c9998b33..d2e6cbbc620 100644 --- a/lib/util/charset/util_str.c +++ b/lib/util/charset/util_str.c @@ -47,6 +47,11 @@ _PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle, c1 = next_codepoint_handle(iconv_handle, s1, &size1); c2 = next_codepoint_handle(iconv_handle, s2, &size2); + if (c1 == INVALID_CODEPOINT || + c2 == INVALID_CODEPOINT) { + return strcasecmp(s1, s2); + } + s1 += size1; s2 += size2; @@ -54,22 +59,6 @@ _PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle, continue; } - if (c1 == INVALID_CODEPOINT || - c2 == INVALID_CODEPOINT) { - /* - * Fall back to byte - * comparison. We must - * step back by the codepoint - * length we just incremented - * - otherwise we are not - * checking the bytes that - * failed the conversion. - */ - s1 -= size1; - s2 -= size2; - return strcasecmp(s1, s2); - } - if (toupper_m(c1) != toupper_m(c2)) { return c1 - c2; } @@ -107,27 +96,9 @@ _PUBLIC_ int strncasecmp_m_handle(struct smb_iconv_handle *iconv_handle, c1 = next_codepoint_handle(iconv_handle, s1, &size1); c2 = next_codepoint_handle(iconv_handle, s2, &size2); - s1 += size1; - s2 += size2; - - if (c1 == c2) { - continue; - } - if (c1 == INVALID_CODEPOINT || c2 == INVALID_CODEPOINT) { /* - * Fall back to byte - * comparison. We must - * step back by the codepoint - * length we just incremented - * by - otherwise we are not - * checking the bytes that - * failed the conversion. - */ - s1 -= size1; - s2 -= size2; - /* * n was specified in characters, * now we must convert it to bytes. * As bytes are the smallest @@ -139,12 +110,19 @@ _PUBLIC_ int strncasecmp_m_handle(struct smb_iconv_handle *iconv_handle, * to be n characters long, so we are * guaranteed to be able to look at the * (n remaining + size1) bytes from the - * new (s1 - size1) position). + * s1 position). */ n += size1; return strncasecmp(s1, s2, n); } + s1 += size1; + s2 += size2; + + if (c1 == c2) { + continue; + } + if (toupper_m(c1) != toupper_m(c2)) { return c1 - c2; } |