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)
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

index 9f8ef6d..206770d 100644 (file)
@@ -166,7 +166,7 @@ bad_name:
                fprintf(stderr, "efivar: %m\n");
                exit(1);
        }
-       strncpy(name_buf, guid_name + name_pos, name_len);
+       strcpy(name_buf, guid_name + name_pos);
        *name = name_buf;
 }