Re: [PATCH] test: unicode: fix a sizeof() vs ARRAY_SIZE() bug
On Thu, Jul 27, 2023 at 10:12:58AM +0300, Dan Carpenter wrote: > 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 Applied to u-boot/next, thanks! -- Tom signature.asc Description: PGP signature
[PATCH] 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 --- test/unicode_ut.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unicode_ut.c b/test/unicode_ut.c index b27d7116b9ee..62ff5d10bf94 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, _src, sizeof(buf)); + ret = u16_strlcat(buf, _src, ARRAY_SIZE(buf)); ut_asserteq(1, 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(5, 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, _src, sizeof(buf)); + ret = u16_strlcat(buf, _src, ARRAY_SIZE(buf)); ut_asserteq(6, ret); ut_assert(!unicode_test_u16_strcmp(buf, dest, 40)); -- 2.39.2
Re: [PATCH] test: unicode: fix a sizeof() vs ARRAY_SIZE() bug
On 7/27/23 09:12, Dan Carpenter wrote: The u16_strlcat() is in units of u16 not bytes. So the limit needs to be ARRAY_SIZE() instead of sizeof(). Reviewed-by: Heinrich Schuchardt Signed-off-by: Dan Carpenter --- test/unicode_ut.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unicode_ut.c b/test/unicode_ut.c index b27d7116b9ee..62ff5d10bf94 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, _src, sizeof(buf)); + ret = u16_strlcat(buf, _src, ARRAY_SIZE(buf)); ut_asserteq(1, 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(5, 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, _src, sizeof(buf)); + ret = u16_strlcat(buf, _src, ARRAY_SIZE(buf)); ut_asserteq(6, ret); ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));