OSDN Git Service

Work around -Werror=stringop-overflow= being daft.
authorPeter Jones <pjones@redhat.com>
Tue, 13 Mar 2018 21:10:56 +0000 (17:10 -0400)
committerPeter Jones <pjones@redhat.com>
Tue, 13 Mar 2018 21:10:56 +0000 (17:10 -0400)
commit7461d47cddf1cb27b1aeb646e1cdc9f7ecc6219a
treed194928734fbf6d552f07ab0f85ed0c3ee875974
parentffc9d1621adae3e4c6e566eb3b303f3749381f41
Work around -Werror=stringop-overflow= being daft.

With:

len = strlen(foo + offset) + 1;
buf = calloc(1, len);
if (!buf)
err(1, "out of memory");
strncpy(buf, foo+offset, len);

-Wstringop-overflow complains:

efivar.c:169:2: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  strncpy(name_buf, guid_name + name_pos, name_len);
  ^
efivar.c:163:13: note: length computed here
  name_len = strlen(guid_name + name_pos) + 1;
             ^
lto1: all warnings being treated as errors

Which... Duh, so was the allocation it's writing into.  So what?

Signed-off-by: Peter Jones <pjones@redhat.com>
src/efivar.c