* [PATCH] test: unicode: fix a sizeof() vs ARRAY_SIZE() bug
@ 2023-07-27 7:12 Dan Carpenter
2023-07-27 8:50 ` Heinrich Schuchardt
2023-08-09 1:40 ` Tom Rini
0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2023-07-27 7:12 UTC (permalink / raw)
To: Heinrich Schuchardt, Masahisa Kojima; +Cc: Ilias Apalodimas, u-boot
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 <dan.carpenter@linaro.org>
---
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, &null_src, sizeof(buf));
+ ret = u16_strlcat(buf, &null_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, &null_src, sizeof(buf));
+ ret = u16_strlcat(buf, &null_src, ARRAY_SIZE(buf));
ut_asserteq(6, ret);
ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] test: unicode: fix a sizeof() vs ARRAY_SIZE() bug
2023-07-27 7:12 [PATCH] test: unicode: fix a sizeof() vs ARRAY_SIZE() bug Dan Carpenter
@ 2023-07-27 8:50 ` Heinrich Schuchardt
2023-08-09 1:40 ` Tom Rini
1 sibling, 0 replies; 3+ messages in thread
From: Heinrich Schuchardt @ 2023-07-27 8:50 UTC (permalink / raw)
To: Dan Carpenter; +Cc: Ilias Apalodimas, u-boot, Masahisa Kojima
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 <xypron.glpk@gmx.de>
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> ---
> 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, &null_src, sizeof(buf));
> + ret = u16_strlcat(buf, &null_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, &null_src, sizeof(buf));
> + ret = u16_strlcat(buf, &null_src, ARRAY_SIZE(buf));
> ut_asserteq(6, ret);
> ut_assert(!unicode_test_u16_strcmp(buf, dest, 40));
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] test: unicode: fix a sizeof() vs ARRAY_SIZE() bug
2023-07-27 7:12 [PATCH] test: unicode: fix a sizeof() vs ARRAY_SIZE() bug Dan Carpenter
2023-07-27 8:50 ` Heinrich Schuchardt
@ 2023-08-09 1:40 ` Tom Rini
1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2023-08-09 1:40 UTC (permalink / raw)
To: Dan Carpenter
Cc: Heinrich Schuchardt, Masahisa Kojima, Ilias Apalodimas, u-boot
[-- Attachment #1: Type: text/plain, Size: 290 bytes --]
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 <dan.carpenter@linaro.org>
Applied to u-boot/next, thanks!
--
Tom
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-09 1:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-27 7:12 [PATCH] test: unicode: fix a sizeof() vs ARRAY_SIZE() bug Dan Carpenter
2023-07-27 8:50 ` Heinrich Schuchardt
2023-08-09 1:40 ` Tom Rini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox