This is the mail archive of the gdb-patches@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]

[PATCH 16/26] -Wpointer-sign: remote-mips.c.


remote-mips.c has a bunch of -Wpointer-sign warnings:

../../src/gdb/remote-mips.c: In function âmips_receive_packetâ:
../../src/gdb/remote-mips.c:1128:7: error: pointer targets in passing argument 2 of âmips_cksumâ differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:830:1: note: expected âconst unsigned char *â but argument is of type âchar *â
../../src/gdb/remote-mips.c:1135:7: error: pointer targets in passing argument 2 of âmips_cksumâ differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:830:1: note: expected âconst unsigned char *â but argument is of type âchar *â
../../src/gdb/remote-mips.c: In function âmips_load_srecâ:
../../src/gdb/remote-mips.c:2830:12: error: pointer targets in passing argument 4 of âmips_make_srecâ differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:134:12: note: expected âunsigned char *â but argument is of type âchar *â
../../src/gdb/remote-mips.c: In function âpmon_zerosetâ:
../../src/gdb/remote-mips.c:3030:3: error: pointer targets in passing argument 4 of âpmon_makeb64â differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:2977:1: note: expected âint *â but argument is of type âunsigned int *â
../../src/gdb/remote-mips.c: In function âpmon_make_fastrecâ:
../../src/gdb/remote-mips.c:3124:6: error: pointer targets in passing argument 3 of âpmon_zerosetâ differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:3025:1: note: expected âint *â but argument is of type âunsigned int *â
../../src/gdb/remote-mips.c:3126:4: error: pointer targets in passing argument 4 of âpmon_makeb64â differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:2977:1: note: expected âint *â but argument is of type âunsigned int *â
../../src/gdb/remote-mips.c:3148:3: error: pointer targets in passing argument 3 of âpmon_zerosetâ differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:3025:1: note: expected âint *â but argument is of type âunsigned int *â
../../src/gdb/remote-mips.c:3153:3: error: pointer targets in passing argument 3 of âpmon_zerosetâ differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:3025:1: note: expected âint *â but argument is of type âunsigned int *â
../../src/gdb/remote-mips.c:3154:8: error: pointer targets in passing argument 4 of âpmon_makeb64â differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:2977:1: note: expected âint *â but argument is of type âunsigned int *â
../../src/gdb/remote-mips.c: In function âpmon_load_fastâ:
../../src/gdb/remote-mips.c:3423:2: error: pointer targets in passing argument 4 of âpmon_makeb64â differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:2977:1: note: expected âint *â but argument is of type âunsigned int *â
../../src/gdb/remote-mips.c:3457:4: error: pointer targets in passing argument 3 of âpmon_checksetâ differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:3051:1: note: expected âint *â but argument is of type âunsigned int *â
../../src/gdb/remote-mips.c:3484:8: error: pointer targets in passing argument 3 of âpmon_zerosetâ differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:3025:1: note: expected âint *â but argument is of type âunsigned int *â
../../src/gdb/remote-mips.c:3489:3: error: pointer targets in passing argument 3 of âpmon_checksetâ differ in signedness [-Werror=pointer-sign]
../../src/gdb/remote-mips.c:3051:1: note: expected âint *â but argument is of type âunsigned int *â

The mips packet payload is ASCII, so it makes sense for
mips_send_packet and mips_receive_packet to expose 'char *'-based
interfaces, as currently they do.  But, mips packets have a binary
header, so if you look at e.g., mips_receive_packet's implementation,
you'll see "unsigned char" buffers in use.  I find it the most natural
to make the payload pointer passed to mips_cksum 'char *' too.

The other changes are straightforward adjustments -- a checksum is
naturally unsigned, and there's one point where we're reading a bfd section.

gdb/
2013-04-11  Pedro Alves  <palves@redhat.com>

	* remote-mips.c (mips_cksum): Rename 'data' parameter to 'datastr'
	and change its type to 'const char *'.  Adjust.
	(mips_send_packet): Add cast to 'char *', and remove cast to
	'unsigned char *'.
	(mips_receive_packet): Remove cast to 'unsigned char *'.
	(mips_load_srec): Use bfd_byte.
	(pmon_makeb64, pmon_zeroset): Make 'chksum' parameter unsigned.
	(pmon_checkset): Make 'value' parameter unsigned.
---
 gdb/remote-mips.c |   32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/gdb/remote-mips.c b/gdb/remote-mips.c
index 85002ec..3b65b59 100644
--- a/gdb/remote-mips.c
+++ b/gdb/remote-mips.c
@@ -63,7 +63,7 @@ static int mips_receive_trailer (unsigned char *trlr, int *pgarbage,
 				 int *pch, int timeout);
 
 static int mips_cksum (const unsigned char *hdr,
-		       const unsigned char *data, int len);
+		       const char *data, int len);
 
 static void mips_send_packet (const char *s, int get_ack);
 
@@ -108,12 +108,12 @@ static void mips_files_info (struct target_ops *ignore);
 
 static void mips_mourn_inferior (struct target_ops *ops);
 
-static int pmon_makeb64 (unsigned long v, char *p, int n, int *chksum);
+static int pmon_makeb64 (unsigned long v, char *p, int n, unsigned int *chksum);
 
-static int pmon_zeroset (int recsize, char **buff, int *amount,
+static int pmon_zeroset (int recsize, char **buff, unsigned int *amount,
 			 unsigned int *chksum);
 
-static int pmon_checkset (int recsize, char **buff, int *value);
+static int pmon_checkset (int recsize, char **buff, unsigned int *value);
 
 static void pmon_make_fastrec (char **outbuf, unsigned char *inbuf,
 			       int *inptr, int inamount, int *recsize,
@@ -824,12 +824,13 @@ mips_receive_trailer (unsigned char *trlr, int *pgarbage,
 }
 
 /* Get the checksum of a packet.  HDR points to the packet header.
-   DATA points to the packet data.  LEN is the length of DATA.  */
+   DATASTR points to the packet data.  LEN is the length of DATASTR.  */
 
 static int
-mips_cksum (const unsigned char *hdr, const unsigned char *data, int len)
+mips_cksum (const unsigned char *hdr, const char *datastr, int len)
 {
   const unsigned char *p;
+  const unsigned char *data = (const unsigned char *) datastr;
   int c;
   int cksum;
 
@@ -872,7 +873,7 @@ mips_send_packet (const char *s, int get_ack)
 
   memcpy (packet + HDR_LENGTH, s, len);
 
-  cksum = mips_cksum (packet, packet + HDR_LENGTH, len);
+  cksum = mips_cksum (packet, (char *) packet + HDR_LENGTH, len);
   packet[HDR_LENGTH + len + TRLR_INDX_CSUM1] = TRLR_SET_CSUM1 (cksum);
   packet[HDR_LENGTH + len + TRLR_INDX_CSUM2] = TRLR_SET_CSUM2 (cksum);
   packet[HDR_LENGTH + len + TRLR_INDX_CSUM3] = TRLR_SET_CSUM3 (cksum);
@@ -976,8 +977,7 @@ mips_send_packet (const char *s, int get_ack)
 
 	  /* If the checksum does not match the trailer checksum, this
 	     is a bad packet; ignore it.  */
-	  if (mips_cksum (hdr, (unsigned char *) NULL, 0)
-	      != TRLR_GET_CKSUM (trlr))
+	  if (mips_cksum (hdr, NULL, 0) != TRLR_GET_CKSUM (trlr))
 	    continue;
 
 	  if (remote_debug > 0)
@@ -1142,7 +1142,7 @@ mips_receive_packet (char *buff, int throw_error, int timeout)
       ack[HDR_INDX_LEN1] = HDR_SET_LEN1 (0, 0, mips_receive_seq);
       ack[HDR_INDX_SEQ] = HDR_SET_SEQ (0, 0, mips_receive_seq);
 
-      cksum = mips_cksum (ack, (unsigned char *) NULL, 0);
+      cksum = mips_cksum (ack, NULL, 0);
 
       ack[HDR_LENGTH + TRLR_INDX_CSUM1] = TRLR_SET_CSUM1 (cksum);
       ack[HDR_LENGTH + TRLR_INDX_CSUM2] = TRLR_SET_CSUM2 (cksum);
@@ -1183,7 +1183,7 @@ mips_receive_packet (char *buff, int throw_error, int timeout)
   ack[HDR_INDX_LEN1] = HDR_SET_LEN1 (0, 0, mips_receive_seq);
   ack[HDR_INDX_SEQ] = HDR_SET_SEQ (0, 0, mips_receive_seq);
 
-  cksum = mips_cksum (ack, (unsigned char *) NULL, 0);
+  cksum = mips_cksum (ack, NULL, 0);
 
   ack[HDR_LENGTH + TRLR_INDX_CSUM1] = TRLR_SET_CSUM1 (cksum);
   ack[HDR_LENGTH + TRLR_INDX_CSUM2] = TRLR_SET_CSUM2 (cksum);
@@ -2781,7 +2781,8 @@ mips_load_srec (char *args)
 {
   bfd *abfd;
   asection *s;
-  char *buffer, srec[1024];
+  char srec[1024];
+  bfd_byte *buffer;
   unsigned int i;
   unsigned int srec_frame = 200;
   int reclen;
@@ -2974,7 +2975,7 @@ static char encoding[] =
    characters written into the buffer.  */
 
 static int
-pmon_makeb64 (unsigned long v, char *p, int n, int *chksum)
+pmon_makeb64 (unsigned long v, char *p, int n, unsigned int *chksum)
 {
   int count = (n / 6);
 
@@ -3022,7 +3023,8 @@ pmon_makeb64 (unsigned long v, char *p, int n, int *chksum)
    escape sequence into the data stream.  */
 
 static int
-pmon_zeroset (int recsize, char **buff, int *amount, unsigned int *chksum)
+pmon_zeroset (int recsize, char **buff,
+	      unsigned int *amount, unsigned int *chksum)
 {
   int count;
 
@@ -3048,7 +3050,7 @@ pmon_zeroset (int recsize, char **buff, int *amount, unsigned int *chksum)
    the record elements added by this call.  */
 
 static int
-pmon_checkset (int recsize, char **buff, int *value)
+pmon_checkset (int recsize, char **buff, unsigned int *value)
 {
   int count;
 


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