From 0a0242582f134c9994bbad77a57f64d388cf9e19 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Sun, 18 Mar 2018 21:32:19 -0700
Subject: [PATCH 13/58] maint: avoid -Wstringop-truncation warnings from
 upcoming GCC8

* src/create.c (start_private_header, start_header): Convert
trivial uses of strncpy to memcpy, to avoid warnings like this:
In function 'strncpy',
    inlined from 'start_private_header' at create.c:522:3:
/usr/include/bits/string_fortified.h:106:10: warning: \
  '__builtin_strncpy' output truncated before terminating nul \
  copying 2 bytes from a string of the same length \
  [-Wstringop-truncation]
---
 src/create.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/create.c b/src/create.c
index 35bcf5b..7737c52 100644
--- a/src/create.c
+++ b/src/create.c
@@ -518,8 +518,8 @@ start_private_header (const char *name, size_t size, time_t t)
   MODE_TO_CHARS (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH, header->header.mode);
   UID_TO_CHARS (0, header->header.uid);
   GID_TO_CHARS (0, header->header.gid);
-  strncpy (header->header.magic, TMAGIC, TMAGLEN);
-  strncpy (header->header.version, TVERSION, TVERSLEN);
+  memcpy (header->header.magic, TMAGIC, TMAGLEN);
+  memcpy (header->header.version, TVERSION, TVERSLEN);
   return header;
 }
 
@@ -917,8 +917,8 @@ start_header (struct tar_stat_info *st)
 
     case POSIX_FORMAT:
     case USTAR_FORMAT:
-      strncpy (header->header.magic, TMAGIC, TMAGLEN);
-      strncpy (header->header.version, TVERSION, TVERSLEN);
+      memcpy (header->header.magic, TMAGIC, TMAGLEN);
+      memcpy (header->header.version, TVERSION, TVERSLEN);
       break;
 
     default:
-- 
2.19.1

