1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

util/charset: Include final UTF‐16 code unit in length calculation loop

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>
This commit is contained in:
Joseph Sutton 2023-11-14 14:38:48 +13:00 committed by Andrew Bartlett
parent 516f35b5a1
commit 74a5a3b74e

View 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;