target.c: fix -Wpointer-sign
authorPedro Alves <palves@redhat.com>
Thu, 7 Mar 2013 23:53:12 +0000 (23:53 +0000)
committerPedro Alves <palves@redhat.com>
Thu, 7 Mar 2013 23:53:12 +0000 (23:53 +0000)
$ make WERROR_CFLAGS="-Wpointer-sign -Werror" target.o -k 2>&1 1>/dev/null
../../src/gdb/target.c: In function ‘target_read_stralloc’:
../../src/gdb/target.c:2376:3: error: pointer targets in passing argument 1 of ‘strlen’ differ in signedness [-Werror=pointer-sign]
In file included from build-gnulib/import/string.h:27:0,
                 from ../../src/gdb/common/gdb_string.h:24,
                 from ../../src/gdb/target.c:24:
/usr/include/string.h:399:15: note: expected ‘const char *’ but argument is of type ‘gdb_byte *’
...

This is about the same as the previous patch.

Functions that take or return ascii-ish string arguments usually use
char* for parameters/return.  That means that at points we call into
target methods that work with binary blobs, we need casts to/from
gdb_byte*/char*.  To choose which type for the variables, I usually go
based on which requires the fewer casts, and what the contents of the
variable are supposed to hold, which often gives the same answer.

gdb/
2013-03-07  Pedro Alves  <palves@redhat.com>

* target.c (target_read_stralloc, target_fileio_read_alloc):
*Cast pointer to 'gdb_byte *' in target call.

gdb/ChangeLog
gdb/target.c

index 29203fe3ff7978c53eda4d241a4c54a9cbbdc03b..da506b4d1ed88e2de95e24f94c733f52935e4ebd 100644 (file)
@@ -1,3 +1,8 @@
+2013-03-07  Pedro Alves  <palves@redhat.com>
+
+       * target.c (target_read_stralloc, target_fileio_read_alloc):
+       *Cast pointer to 'gdb_byte *' in target call.
+
 2013-03-07  Pedro Alves  <palves@redhat.com>
 
        * corefile.c (read_memory_string): Cast pointer to gdb_byte* in
index ecb1325a410b246fc8905d29d7d32c735a58203c..eaf8b31f19e582478119a0b1a218863b3a4edb46 100644 (file)
@@ -2359,10 +2359,11 @@ char *
 target_read_stralloc (struct target_ops *ops, enum target_object object,
                      const char *annex)
 {
-  gdb_byte *buffer;
+  char *buffer;
   LONGEST i, transferred;
 
-  transferred = target_read_alloc_1 (ops, object, annex, &buffer, 1);
+  transferred = target_read_alloc_1 (ops, object, annex,
+                                    (gdb_byte **) &buffer, 1);
 
   if (transferred < 0)
     return NULL;
@@ -2382,7 +2383,7 @@ target_read_stralloc (struct target_ops *ops, enum target_object object,
        break;
       }
 
-  return (char *) buffer;
+  return buffer;
 }
 
 /* Memory transfer methods.  */
@@ -3522,10 +3523,11 @@ target_fileio_read_alloc (const char *filename, gdb_byte **buf_p)
 char *
 target_fileio_read_stralloc (const char *filename)
 {
-  gdb_byte *buffer;
+  char *buffer;
   LONGEST i, transferred;
 
-  transferred = target_fileio_read_alloc_1 (filename, &buffer, 1);
+  transferred = target_fileio_read_alloc_1 (filename,
+                                           (gdb_byte **) &buffer, 1);
 
   if (transferred < 0)
     return NULL;
@@ -3545,7 +3547,7 @@ target_fileio_read_stralloc (const char *filename)
        break;
       }
 
-  return (char *) buffer;
+  return buffer;
 }