dmx: Silence a string truncation warning.

../hw/dmx/config/dmxparse.c: In function ‘dmxConfigCreateOption’:
../hw/dmx/config/dmxparse.c:385:13: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
             strncpy(option->string + offset, p->string, len);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../hw/dmx/config/dmxparse.c:383:23: note: length computed here
             int len = strlen(p->string);
                       ^~~~~~~~~~~~~~~~~

The thing it's warning about is intentional, the surrounding code does
its own nul-termination. Make that obvious by using memcpy instead.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Acked-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Adam Jackson 2018-04-05 12:48:26 -04:00
parent 176f26e96a
commit d13cd3862e

View File

@ -382,7 +382,7 @@ dmxConfigCreateOption(DMXConfigTokenPtr pStart,
if (p->string) { if (p->string) {
int len = strlen(p->string); int len = strlen(p->string);
strncpy(option->string + offset, p->string, len); memcpy(option->string + offset, p->string, len);
offset += len; offset += len;
if (p->next) if (p->next)
option->string[offset++] = ' '; option->string[offset++] = ' ';