gcc 9.1.0 reports
enable_events.c:827:2: warning: ‘strncpy’ output truncated copying 9 bytes from a string of length 11 [-Wstringop-truncation]
827 | strncpy(ret, preamble, length);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc seems confused and using "sizeof" the preamble seems to make
it understand the code flow and not generate the warning anymore.
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
{
int length = 0;
int i;
- const char *preamble = " excluding ";
+ const char preamble[] = " excluding ";
char *ret;
int count = names ? strutils_array_of_strings_len(names) : 0;
length += strlen(names[i]) + 4;
}
- /* add length of preamble + one for NUL - one for last (missing) comma */
- length += strlen(preamble);
- ret = zmalloc(length + 1);
+ length += sizeof(preamble);
+ ret = zmalloc(length);
if (!ret) {
return NULL;
}