main: Don't add int to string
authorSimon Marchi <simon.marchi@ericsson.com>
Sun, 25 Jun 2017 10:57:13 +0000 (12:57 +0200)
committerSimon Marchi <simon.marchi@ericsson.com>
Sun, 25 Jun 2017 10:57:13 +0000 (12:57 +0200)
clang shows this warning:

  /home/emaisin/src/binutils-gdb/gdb/main.c:227:56: error: adding 'int' to a string does not append to the string [-Werror,-Wstring-plus-int]
                char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
                                                 ~~~~~~~~~~~~~~~^~~~~~~~~~~~~
  /home/emaisin/src/binutils-gdb/gdb/main.c:227:56: note: use array indexing to silence this warning
                char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
                                                                ^
                                                 &              [            ]

It's quite easy to get rid of it by using &foo[len] instead of foo + len.
I think this warning is relevant to keep enabled, because it can be an
easy mistake to do.

This warning is already discussed here in GCC bugzilla:

  https://gcc.gnu.org/ml/gcc-patches/2017-06/msg00729.html

and a patch series for it was submitted very recently.

gdb/ChangeLog:

* main.c (get_init_files): Replace "SYSTEM_GDBINIT +
datadir_len" with "&SYSTEM_GDBINIT[datadir_len]".

gdb/ChangeLog
gdb/main.c

index 7c48bf4ba778da8a11b345409e9a0d5e27216a53..e1ad84a4d24f99f8732d17992920e3ab682d3cb0 100644 (file)
@@ -1,3 +1,8 @@
+2017-06-25  Simon Marchi  <simon.marchi@ericsson.com>
+
+       * main.c (get_init_files): Replace "SYSTEM_GDBINIT +
+       datadir_len" with "&SYSTEM_GDBINIT[datadir_len]".
+
 2017-06-25  Simon Marchi  <simon.marchi@ericsson.com>
 
        * dtrace-probe.c (dtrace_process_dof_probe): Put semi-colon on
index df4b1110d6b59cb9316c2c51bd93141102a4d632..9813041bca32620cd4f40ad45494ce15606704f7 100644 (file)
@@ -224,7 +224,7 @@ get_init_files (const char **system_gdbinit,
            {
              /* Append the part of SYSTEM_GDBINIT that follows GDB_DATADIR
                 to gdb_datadir.  */
-             char *tmp_sys_gdbinit = xstrdup (SYSTEM_GDBINIT + datadir_len);
+             char *tmp_sys_gdbinit = xstrdup (&SYSTEM_GDBINIT[datadir_len]);
              char *p;
 
              for (p = tmp_sys_gdbinit; IS_DIR_SEPARATOR (*p); ++p)