diff options
Diffstat (limited to 'lib/util/charset/util_str.c')
-rw-r--r-- | lib/util/charset/util_str.c | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/lib/util/charset/util_str.c b/lib/util/charset/util_str.c index 688ab5a0a1c..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,12 +59,6 @@ _PUBLIC_ int strcasecmp_m_handle(struct smb_iconv_handle *iconv_handle, continue; } - if (c1 == INVALID_CODEPOINT || - c2 == INVALID_CODEPOINT) { - /* what else can we do?? */ - return strcasecmp(s1, s2); - } - if (toupper_m(c1) != toupper_m(c2)) { return c1 - c2; } @@ -97,6 +96,26 @@ _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); + if (c1 == INVALID_CODEPOINT || + c2 == INVALID_CODEPOINT) { + /* + * n was specified in characters, + * now we must convert it to bytes. + * As bytes are the smallest + * character unit, the following + * increment and strncasecmp is always + * safe. + * + * The source string was already known + * to be n characters long, so we are + * guaranteed to be able to look at the + * (n remaining + size1) bytes from the + * s1 position). + */ + n += size1; + return strncasecmp(s1, s2, n); + } + s1 += size1; s2 += size2; @@ -104,12 +123,6 @@ _PUBLIC_ int strncasecmp_m_handle(struct smb_iconv_handle *iconv_handle, continue; } - if (c1 == INVALID_CODEPOINT || - c2 == INVALID_CODEPOINT) { - /* what else can we do?? */ - return strcasecmp(s1, s2); - } - if (toupper_m(c1) != toupper_m(c2)) { return c1 - c2; } |