From: Jim Meyering Date: Mon, 19 Mar 2018 04:20:28 +0000 (-0700) Subject: maint: avoid -Wstringop-truncation warnings upcoming GCC8 X-Git-Tag: release_1_31~31 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2baa531ce53d5876d34f941a97b5041573da453a;p=thirdparty%2Ftar.git 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] --- diff --git a/src/buffer.c b/src/buffer.c index 063e1bea..b710c6a9 100644 --- a/src/buffer.c +++ b/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);