Skip to content
Snippets Groups Projects
Commit 2b3aff86 authored by Georgiy Lebedev's avatar Georgiy Lebedev Committed by Vladimir Davydov
Browse files

test: fix number to string conversion in tuple format map test

Though the range of values of the number being converted to string in the
tuple format map test never exceeds 10, GCC 12 issues warnings about the
size of the buffer to which the string version of the number is written:

NO_WRAP
```
test/unit/tuple_format_map.c:256:53: error: ‘%zu’ directive output may be truncated writing between 1 and 19 bytes into a region of size 4 [-Werror=format-
truncation=]
  256 |                 snprintf(name, lengthof(name), "test%zu", i);
      |                                                     ^~~
test/unit/tuple_format_map.c:256:48: note: directive argument in the range [0, 9223372036854775807]
  256 |                 snprintf(name, lengthof(name), "test%zu", i);
      |                                                ^~~~~~~~~
test/unit/tuple_format_map.c:256:17: note: ‘snprintf’ output between 6 and 24 bytes into a destination of size 8
  256 |                 snprintf(name, lengthof(name), "test%zu", i);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
NO_WRAP

Let's make GCC happy and increase all the buffer sizes to 32.

NO_CHANGELOG=<build fix>
NO_DOC=<build fix>
NO_TEST=<build fix>
parent b6fec82a
No related branches found
No related tags found
No related merge requests found
......@@ -68,7 +68,7 @@ test_tuple_format_map_only_cache(void)
size_t format_data_len[TUPLE_FORMAT_MAP_CACHE_SIZE];
uint16_t format_ids[TUPLE_FORMAT_MAP_CACHE_SIZE];
for (ssize_t i = 0; i < TUPLE_FORMAT_MAP_CACHE_SIZE; ++i) {
char num[4];
char num[32];
snprintf(num, lengthof(num), "%zu", i);
size_t len = mp_format(p, lengthof(buf) - (p - buf),
"[{%s%s}]", "name", num);
......@@ -159,7 +159,7 @@ test_tuple_format_map_cache_and_hash_table(void)
size_t format_data_len[TUPLE_FORMAT_MAP_CACHE_SIZE + 2];
uint16_t format_ids[TUPLE_FORMAT_MAP_CACHE_SIZE + 2];
for (ssize_t i = 0; i < TUPLE_FORMAT_MAP_CACHE_SIZE + 2; ++i) {
char num[4];
char num[32];
snprintf(num, lengthof(num), "%zu", i);
size_t len = mp_format(p, lengthof(buf) - (p - buf),
"[{%s%s}]", "name", num);
......@@ -252,7 +252,7 @@ test_tuple_format_map_duplicate(size_t format_count, size_t add_count)
tuple_format_map_create_empty(&map);
for (size_t i = 0; i < format_count; ++i) {
char name[8];
char name[32];
snprintf(name, lengthof(name), "test%zu", i);
char str_format[16];
size_t len = mp_format(str_format, lengthof(str_format),
......@@ -340,7 +340,7 @@ test_tuple_format_map_decode_from_msgpack(void)
header();
struct tuple_format *format[2];
char name[2][8];
char name[2][32];
for (size_t i = 0; i < lengthof(format); i++) {
snprintf(name[i], lengthof(name[i]), "test%zu", i);
char str_format[16];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment