This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] main: Don't add int to string


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cc75e0fdaeb179efc66ddd1cb1b6da40e6adacc1

commit cc75e0fdaeb179efc66ddd1cb1b6da40e6adacc1
Author: Simon Marchi <simon.marchi@ericsson.com>
Date:   Sun Jun 25 12:57:13 2017 +0200

    main: Don't add int to string
    
    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]".

Diff:
---
 gdb/ChangeLog | 5 +++++
 gdb/main.c    | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7c48bf4..e1ad84a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
 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
 	its own line.
 
diff --git a/gdb/main.c b/gdb/main.c
index df4b111..9813041 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]