]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[GOLD] gcc-11 stringop-overflow warning
authorAlan Modra <amodra@gmail.com>
Mon, 7 Dec 2020 06:46:46 +0000 (17:16 +1030)
committerAlan Modra <amodra@gmail.com>
Mon, 7 Dec 2020 12:06:22 +0000 (22:36 +1030)
I'm unsure why this is deserving of a warning.  Not writing the most
efficient code surely can't be a real problem, but that is what
https://gcc.gnu.org/bugzilla//show_bug.cgi?id=88059#c1 seems to say.

plugin.cc:528:10: error: 'char* strncpy(char*, const char*, size_t)' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  528 |   strncpy(tempdir, dir_template, len);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
plugin.cc:526:22: note: length computed here
  526 |   size_t len = strlen(dir_template) + 1;
      |                ~~~~~~^~~~~~~~~~~~~~

* plugin.cc (Plugin_recorder::init): Replace strncpy with memcpy.

gold/ChangeLog
gold/plugin.cc

index 05a6f26d8fb93499861586542b2cc088d8774c4e..e152e1ed6980ef061d207aa1b79267d58fd2f82c 100644 (file)
@@ -1,3 +1,7 @@
+2020-12-07  Alan Modra  <amodra@gmail.com>
+
+       * plugin.cc (Plugin_recorder::init): Replace strncpy with memcpy.
+
 2020-12-03  Alan Modra  <amodra@gmail.com>
 
        * testsuite/Makefile.am (pr26936a.o): Pass -mx86-used-note=yes.
index 729ddca9f319c6c16c3c550746c3baddbb43db83..fd37957e73c717067a4039188f125470e53cd50b 100644 (file)
@@ -525,7 +525,7 @@ Plugin_recorder::init()
 
   size_t len = strlen(dir_template) + 1;
   char* tempdir = new char[len];
-  strncpy(tempdir, dir_template, len);
+  memcpy(tempdir, dir_template, len);
 
   // Create the log file.
   std::string logname(tempdir);