Skip to content

Commit

Permalink
tests: net: ip-addr: Fix compiler warning
Browse files Browse the repository at this point in the history
Building with Zephyr SDK 0.16.5 revealed a minor bug with the buffer
size provided to snprintk():
  specified bound 38 exceeds destination size 20 [-Wstringop-overflow=]

As we provide the buffer to snprintk() with an offset, the actual
buffer size should be reduced by that offset value.

Signed-off-by: Robert Lubos <[email protected]>
  • Loading branch information
rlubos authored and carlescufi committed Feb 2, 2024
1 parent 32fd2f5 commit c6f2f2c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/net/ip-addr/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ static struct net_if *default_iface;
"Test %s failed.\n", expected); \
} while (0)

#define LL_ADDR_STR_SIZE sizeof("xx:xx:xx:xx:xx:xx")

#define TEST_LL_6_TWO(a, b, c, d, e, f, expected) \
do { \
uint8_t ll1[] = { a, b, c, d, e, f }; \
uint8_t ll2[] = { f, e, d, c, b, a }; \
char out[2 * sizeof("xx:xx:xx:xx:xx:xx") + 1 + 1]; \
char out[2 * LL_ADDR_STR_SIZE + 1 + 1]; \
snprintk(out, sizeof(out), "%s ", \
net_sprint_ll_addr(ll1, sizeof(ll1))); \
snprintk(out + sizeof("xx:xx:xx:xx:xx:xx"), \
sizeof(out), "%s", \
snprintk(out + LL_ADDR_STR_SIZE, \
sizeof(out) - LL_ADDR_STR_SIZE, "%s", \
net_sprint_ll_addr(ll2, sizeof(ll2))); \
zassert_false(strcmp(out, expected), \
"Test %s failed, got %s\n", expected, \
Expand Down

0 comments on commit c6f2f2c

Please sign in to comment.