Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 16/26] -Wpointer-sign: remote-mips.c.
Date: Fri, 12 Apr 2013 02:30:00 -0000	[thread overview]
Message-ID: <20130411230052.16791.58243.stgit@brno.lan> (raw)
In-Reply-To: <20130411225847.16791.29283.stgit@brno.lan>

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;
 


  parent reply	other threads:[~2013-04-11 23:00 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11 23:00 [PATCH 00/26] Make GDB -Wpointer-sign clean Pedro Alves
2013-04-11 23:00 ` [PATCH 01/26] -Wpointer-sign: char -> gdb_byte Pedro Alves
2013-04-11 23:00 ` [PATCH 02/26] -Wpointer-sign: gdb_byte -> char Pedro Alves
2013-04-12 12:34   ` Yao Qi
2013-04-12 14:42     ` Pedro Alves
2013-04-11 23:01 ` [PATCH 07/26] ppc-linux-tdep.c: Wrong signness for buffer holding instructions Pedro Alves
2013-04-11 23:01 ` [PATCH 03/26] cris-tdep.c: Use unsigned variable for unsigned command Pedro Alves
2013-04-11 23:01 ` [PATCH 04/26] alpha-tdep.c/mips-tdep.c: "set heuristic-fence-post" is signed/zinteger Pedro Alves
2013-04-11 23:01 ` [PATCH 05/26] mep-tdep.c: Wrong signness for instruction buffer Pedro Alves
2013-04-11 23:01 ` [PATCH 06/26] mips-tdep.c: Wrong signness for local holding PC register Pedro Alves
2013-04-11 23:01 ` [PATCH 12/26] Cast result of obstack_base to gdb_byte * in a couple spots Pedro Alves
2013-04-11 23:01 ` [PATCH 08/26] -Wpointer-sign: s390-tdep.c Pedro Alves
2013-04-11 23:01 ` [PATCH 10/26] -Wpointer-sign: xtensa-tdep.c Pedro Alves
2013-04-11 23:02 ` [PATCH 13/26] serial_write: change prototype to take a void-pointer buffer Pedro Alves
2013-04-12 14:55   ` Pedro Alves
2013-04-19 14:23     ` Pedro Alves
2013-04-19 14:28       ` Eli Zaretskii
2013-04-19 14:28         ` Pedro Alves
2013-04-11 23:02 ` [PATCH 11/26] -Wpointer-sign: alpha-tdep.c Pedro Alves
2013-04-11 23:20 ` [PATCH 14/26] gdb_byte for binary buffer, char for string: remote.c, tracepoint.c Pedro Alves
2013-04-11 23:23 ` [PATCH 15/26] gdb_byte for binary buffer, char for string: common/agent.c Pedro Alves
2013-04-12  2:30 ` Pedro Alves [this message]
2013-04-12  2:32 ` [PATCH 17/26] -Wpointer-sign: python/ Pedro Alves
2013-04-12 20:56   ` Tom Tromey
2013-04-12  6:55 ` [PATCH 18/26] -Wpointer-sign: bookmarks Pedro Alves
2013-04-12  8:58 ` [PATCH 19/26] -Wpointer-sign: coff-pe-read.c: treat strings in PE/COFF data as char * Pedro Alves
2013-04-12  9:06 ` [PATCH 20/26] -Wpointer-sign: xcoffread.c Pedro Alves
2013-04-12  9:32 ` [PATCH 21/26] -Wpointer-sign: dwarf2read.c Pedro Alves
2013-04-12 21:01   ` Tom Tromey
2013-04-12  9:54 ` [PATCH 22/26] -Wpointer-sign: dwarf2-frame.c: Pass unsigned variable to safe_read_uleb128 Pedro Alves
2013-04-12 10:01 ` [PATCH 23/26] -Wpointer-sign: ada-lang.c, ada-tasks.c Pedro Alves
2013-04-12 10:11 ` [PATCH 24/26] -Wpointer-sign: cp-valprint.c Pedro Alves
2013-04-12 10:18 ` [PATCH 25/26] -Wpointer-sign: ctf.c Pedro Alves
2013-04-12 10:39 ` [PATCH 26/26] -Wpointer-sign: record.c Pedro Alves
2013-04-12 11:34 ` [PATCH 09/26] -Wpointer-sign: aarch64-tdep.c Pedro Alves
2013-04-12 14:39 ` [PATCH 00/26] Make GDB -Wpointer-sign clean Yao Qi
2013-04-12 21:44 ` Tom Tromey
2013-04-19 14:13   ` Pedro Alves
2013-04-19 18:17 ` [COMMIT] " Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130411230052.16791.58243.stgit@brno.lan \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox