]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
util/charset: Include final UTF‐16 code unit in length calculation loop
authorJoseph Sutton <josephsutton@catalyst.net.nz>
Tue, 14 Nov 2023 01:38:48 +0000 (14:38 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 15 Nov 2023 22:07:36 +0000 (22:07 +0000)
Change ‘<’ to ‘<=’ so that we check the final UTF‐16 code unit in our
search for the null terminator. This makes no difference to the result:
if we’ve reached the final code unit without finding a terminator, the
final code unit will be included in the length whether it is a null
terminator or not.

Why make this change? We’re about to factor out this loop into a new
function, utf16_len_n(), where including the final code unit *will*
matter.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/util/charset/util_unistr.c

index d81a9c3b70f0d33f47b60b1f92f574156d64aa20..66620fb543290255a1d36000558c8368d09072ee 100644 (file)
@@ -221,7 +221,7 @@ size_t utf16_null_terminated_len_n(const void *src, size_t n)
 {
        size_t len;
 
-       for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ;
+       for (len = 0; (len+2 <= n) && SVAL(src, len); len += 2) ;
 
        if (len+2 <= n) {
                len += 2;