Skip to content

Commit

Permalink
test: unicode: fix a sizeof() vs ARRAY_SIZE() bug
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Dan Carpenter authored and trini committed Aug 8, 2023
1 parent bb34bc0 commit be5f9a7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions test/unicode_ut.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,20 +807,20 @@ 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));

/* src is empty string */
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));

Expand Down

0 comments on commit be5f9a7

Please sign in to comment.