From 74a5a3b74e1388936307da9d06f4d1a816d7613f Mon Sep 17 00:00:00 2001 From: Joseph Sutton Date: Tue, 14 Nov 2023 14:38:48 +1300 Subject: [PATCH] =?utf8?q?util/charset:=20Include=20final=20UTF=E2=80=9016?= =?utf8?q?=20code=20unit=20in=20length=20calculation=20loop?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Andrew Bartlett --- lib/util/charset/util_unistr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c index d81a9c3b70f..66620fb5432 100644 --- a/lib/util/charset/util_unistr.c +++ b/lib/util/charset/util_unistr.c @@ -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; -- 2.47.3