51 lines
1.6 KiB
Diff
51 lines
1.6 KiB
Diff
From 2baa531ce53d5876d34f941a97b5041573da453a Mon Sep 17 00:00:00 2001
|
|
From: Jim Meyering <meyering@fb.com>
|
|
Date: Sun, 18 Mar 2018 21:20:28 -0700
|
|
Subject: [PATCH 12/58] 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]
|
|
---
|
|
src/buffer.c | 14 +++++++++-----
|
|
1 file changed, 9 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/src/buffer.c b/src/buffer.c
|
|
index 063e1be..b710c6a 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);
|
|
--
|
|
2.19.1
|
|
|