public inbox for dwz@sourceware.org
 help / color / mirror / Atom feed
* [committed] Work around spurious stringop-overflow warning
@ 2019-01-01  0:00 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2019-01-01  0:00 UTC (permalink / raw)
  To: dwz, jakub

Hi,

With the previous commit we get with gcc 8 and newer:
...
In function ‘make_temp_file’,
    inlined from ‘make_temp_file’ at dwz.c:12366:1:
dwz.c:12399:3: warning: ‘strncpy’ specified bound depends \
  on the length of the source argument [-Wstringop-overflow=]
12399 |   strncpy (&buf[offset], name, buf_len - offset);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dwz.c: In function ‘make_temp_file’:
dwz.c:12384:14: note: length computed here
12384 |   name_len = strlen (name);
      |              ^~~~~~~~~~~~~
...

This is due to a gcc PR 88059 - "Spurious stringop-overflow warning with
strlen, malloc and strncpy".

Work around this gcc PR by using strcpy instead of strncpy.

Committed to trunk.

Thanks,
- Tom

Work around spurious stringop-overflow warning

2019-10-21  Tom de Vries  <tdevries@suse.de>

	* dwz.c (make_temp_file): Use strcpy instead of strncpy.

---
 dwz.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/dwz.c b/dwz.c
index e762fb7..e940d91 100644
--- a/dwz.c
+++ b/dwz.c
@@ -12393,13 +12393,13 @@ make_temp_file (const char *name)
     return -1;
   offset = 0;
 
-  strncpy (&buf[offset], tmpdir, buf_len - offset);
+  strcpy (&buf[offset], tmpdir);
   offset += strlen (tmpdir);
 
-  strncpy (&buf[offset], name, buf_len - offset);
+  strcpy (&buf[offset], name);
   offset += name_len;
 
-  strncpy (&buf[offset], template_suffix, buf_len - offset);
+  strcpy (&buf[offset], template_suffix);
   offset += strlen (template_suffix);
 
   assert (offset == buf_len - 1);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-10-21 11:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-01  0:00 [committed] Work around spurious stringop-overflow warning Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).