]> git.ipfire.org Git - thirdparty/tar.git/commitdiff
maint: avoid -Wstringop-truncation warnings upcoming GCC8
authorJim Meyering <meyering@fb.com>
Mon, 19 Mar 2018 04:20:28 +0000 (21:20 -0700)
committerSergey Poznyakoff <gray@gnu.org>
Sat, 7 Apr 2018 07:37:16 +0000 (10:37 +0300)
* 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]

src/buffer.c

index 063e1beabd708913dbe2acdcbad1ee6ee5c9106e..b710c6a9dca56d0e6ef12b8e05c894b7ae71b6ac 100644 (file)
@@ -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);