From: Dan Carpenter Date: Thu, 27 Jul 2023 07:12:58 +0000 (+0300) Subject: test: unicode: fix a sizeof() vs ARRAY_SIZE() bug X-Git-Tag: v2025.01-rc5-pxa1908~847^2~40^2~8 X-Git-Url: http://git.dujemihanovic.xyz/%22/img/sics.gif/%22/static/git-favicon.png?a=commitdiff_plain;h=be5f9a77f8bc83a3f93d26a50acc047d2bbee908;p=u-boot.git test: unicode: fix a sizeof() vs ARRAY_SIZE() bug The u16_strlcat() is in units of u16 not bytes. So the limit needs to be ARRAY_SIZE() instead of sizeof(). Signed-off-by: Dan Carpenter --- diff --git a/test/unicode_ut.c b/test/unicode_ut.c index a9356e2b60..1d0d90c2d7 100644 --- a/test/unicode_ut.c +++ b/test/unicode_ut.c @@ -807,12 +807,12 @@ static int unicode_test_u16_strlcat(struct unit_test_state *uts) /* dest and src are empty string */ memset(buf, 0, sizeof(buf)); - ret = u16_strlcat(buf, &null_src, sizeof(buf)); + ret = u16_strlcat(buf, &null_src, ARRAY_SIZE(buf)); ut_asserteq(0, ret); /* dest is empty string */ memset(buf, 0, sizeof(buf)); - ret = u16_strlcat(buf, src, sizeof(buf)); + ret = u16_strlcat(buf, src, ARRAY_SIZE(buf)); ut_asserteq(4, ret); ut_assert(!unicode_test_u16_strcmp(buf, src, 40)); @@ -820,7 +820,7 @@ static int unicode_test_u16_strlcat(struct unit_test_state *uts) memset(buf, 0xCD, (sizeof(buf) - sizeof(u16))); buf[39] = 0; memcpy(buf, dest, sizeof(dest)); - ret = u16_strlcat(buf, &null_src, sizeof(buf)); + ret = u16_strlcat(buf, &null_src, ARRAY_SIZE(buf)); ut_asserteq(5, ret); ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));