Преглед на файлове

maint: avoid -Wstringop-truncation warnings upcoming GCC8

* src/buffer.c (gnu_add_multi_volume_header): Convert a use of
strncpy to memcpy, to avoid this warning:
In function 'strncpy',
    inlined from 'gnu_add_multi_volume_header' at buffer.c:1782:3,
    ...
/usr/include/bits/string_fortified.h:106:10: error: '__builtin_strncpy'\
   specified bound 100 equals destination size \
   [-Werror=stringop-truncation]
Jim Meyering преди 7 години
родител
ревизия
2baa531ce5
променени са 1 файла, в които са добавени 9 реда и са изтрити 5 реда
  1. 9 5
      src/buffer.c

+ 9 - 5
src/buffer.c

@@ -1771,15 +1771,19 @@ gnu_add_multi_volume_header (struct bufmap *map)
 {
   int tmp;
   union block *block = find_next_block ();
+  size_t len = strlen (map->file_name);
 
-  if (strlen (map->file_name) > NAME_FIELD_SIZE)
-    WARN ((0, 0,
-           _("%s: file name too long to be stored in a GNU multivolume header, truncated"),
-           quotearg_colon (map->file_name)));
+  if (len > NAME_FIELD_SIZE)
+    {
+      WARN ((0, 0,
+	     _("%s: file name too long to be stored in a GNU multivolume header, truncated"),
+	     quotearg_colon (map->file_name)));
+      len = NAME_FIELD_SIZE;
+    }
 
   memset (block, 0, BLOCKSIZE);
 
-  strncpy (block->header.name, map->file_name, NAME_FIELD_SIZE);
+  memcpy (block->header.name, map->file_name, len);
   block->header.typeflag = GNUTYPE_MULTIVOL;
 
   OFF_TO_CHARS (map->sizeleft, block->header.size);