]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix build with GCC 8: strncpy -> memcpy
authorYao Qi <yao.qi@linaro.org>
Wed, 22 Nov 2017 12:22:11 +0000 (12:22 +0000)
committerYao Qi <yao.qi@linaro.org>
Wed, 22 Nov 2017 12:22:11 +0000 (12:22 +0000)
Recent gcc 8 trunk emits the warning below,

../../../binutils-gdb/gdb/gdbserver/remote-utils.c:1204:14: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 6 bytes from a string of the same length [-Werror=stringop-truncation]
      strncpy (buf, "watch:", 6);
      ~~~~~~~~^~~~~~~~~~~~~~~~~~

../../binutils-gdb/gdb/cli/cli-decode.c:1118:15: error: ‘char* strncpy(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
       strncpy (cmdtype1 + 1, cmdtype, len - 1);
       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../binutils-gdb/gdb/cli/cli-decode.c:1110:16: note: length computed here
   len = strlen (cmdtype);
         ~~~~~~~^~~~~~~~~
../../binutils-gdb/gdb/cli/cli-decode.c:1120:15: error: ‘char* strncpy(char*, const char*, size_t)’ specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
       strncpy (cmdtype2, cmdtype, len - 1);
       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../binutils-gdb/gdb/cli/cli-decode.c:1110:16: note: length computed here
   len = strlen (cmdtype);
         ~~~~~~~^~~~~~~~~

../../binutils-gdb/gdb/cp-namespace.c:1071:11: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 2 bytes from a string of the same length [-Werror=stringop-truncation]
   strncpy (full_name + scope_length, "::", 2);
   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This patch fixes it by using memcpy instead of strncpy.

gdb:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

* cli/cli-decode.c (help_list): Use memcpy instead of strncpy.
* cp-namespace.c (cp_lookup_transparent_type_loop): Likewise.

gdb/gdbserver:

2017-11-22  Yao Qi  <yao.qi@linaro.org>

* remote-utils.c (prepare_resume_reply): Use memcpy.

gdb/ChangeLog
gdb/cli/cli-decode.c
gdb/cp-namespace.c
gdb/gdbserver/ChangeLog
gdb/gdbserver/remote-utils.c

index 1c77dea873e582e277fdd62f49fdf7ff557b1b9d..a9e7528a87a9027c6c92d91f7089c3db898ff0d2 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-22  Yao Qi  <yao.qi@linaro.org>
+
+       * cli/cli-decode.c (help_list): Use memcpy instead of strncpy.
+       * cp-namespace.c (cp_lookup_transparent_type_loop): Likewise.
+
 2017-11-21  Jerome Guitton  <guitton@adacore.com>
 
        * ravenscar-thread.c (ravenscar_wait): Update inferior ptid
index b9110976b94fcdf84fda5de1806e7371fc381231..6140a1744798d74b8b874134f35ce928af069a10 100644 (file)
@@ -1084,9 +1084,9 @@ help_list (struct cmd_list_element *list, const char *cmdtype,
   if (len)
     {
       cmdtype1[0] = ' ';
-      strncpy (cmdtype1 + 1, cmdtype, len - 1);
+      memcpy (cmdtype1 + 1, cmdtype, len - 1);
       cmdtype1[len] = 0;
-      strncpy (cmdtype2, cmdtype, len - 1);
+      memcpy (cmdtype2, cmdtype, len - 1);
       strcpy (cmdtype2 + len - 1, " sub");
     }
 
index d8817c03726d55291cb2d9491bc6a2aa5bf26674..2a3ffefe0cb3fb25f7a7202309afda4838d35d25 100644 (file)
@@ -1049,7 +1049,7 @@ cp_lookup_transparent_type_loop (const char *name,
 
   full_name = (char *) alloca (scope_length + 2 + strlen (name) + 1);
   strncpy (full_name, scope, scope_length);
-  strncpy (full_name + scope_length, "::", 2);
+  memcpy (full_name + scope_length, "::", 2);
   strcpy (full_name + scope_length + 2, name);
 
   return basic_lookup_transparent_type (full_name);
index d891b2d49fe83209f78c4a21adf570dc05c0e52f..b53fe30173d2de63302de500ec3838747e13fe41 100644 (file)
@@ -1,3 +1,7 @@
+2017-11-22  Yao Qi  <yao.qi@linaro.org>
+
+       * remote-utils.c (prepare_resume_reply): Use memcpy.
+
 2017-11-19  Simon Marchi  <simon.marchi@ericsson.com>
 
        * linux-low.c (kill_one_lwp_callback): Return void, take
index 2e4888a78db928bf7701dd7fe0b0b76d83dde411..2fdbb6f4bd7538596bf626b37b4d7c263815b32e 100644 (file)
@@ -1173,7 +1173,7 @@ prepare_resume_reply (char *buf, ptid_t ptid,
            CORE_ADDR addr;
            int i;
 
-           strncpy (buf, "watch:", 6);
+           memcpy (buf, "watch:", 6);
            buf += 6;
 
            addr = (*the_target->stopped_data_address) ();