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] [C++/mingw] ser-tcp.c casts


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

commit 69e976f8cc902adc5ee8aec24e4a208f4afd51b3
Author: Pedro Alves <palves@redhat.com>
Date:   Tue Nov 17 15:17:45 2015 +0000

    [C++/mingw] ser-tcp.c casts
    
    Fixes a few errors like these:
    
    ../../src/gdb/ser-tcp.c: In function 'int net_open(serial*, const char*)':
    ../../src/gdb/ser-tcp.c:286:73: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
         res = getsockopt (scb->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len);
                                                                             ^
    
    gdb/ChangeLog:
    2015-11-17  Pedro Alves  <palves@redhat.com>
    
    	* ser-tcp.c (net_open) : Cast getsockopt argument to char *
    	instead of void *.  Update comment.
    	(net_read_prim): Cast recv argument to char * instead of void *.
    	(net_write_prim): Cast send argument to char *.  Add comment.

Diff:
---
 gdb/ChangeLog |  7 +++++++
 gdb/ser-tcp.c | 16 ++++++++++------
 2 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index ddd17a7..3bec8cb 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,12 @@
 2015-11-17  Pedro Alves  <palves@redhat.com>
 
+	* ser-tcp.c (net_open) : Cast getsockopt argument to char *
+	instead of void *.  Update comment.
+	(net_read_prim): Cast recv argument to char * instead of void *.
+	(net_write_prim): Cast send argument to char *.  Add comment.
+
+2015-11-17  Pedro Alves  <palves@redhat.com>
+
 	* win32-i386-low.c (update_debug_registers_callback)
 	(win32_get_current_dr): Add cast.
 	* win32-low.c (thread_rec, delete_thread_info)
diff --git a/gdb/ser-tcp.c b/gdb/ser-tcp.c
index ce40b61..36196f3 100644
--- a/gdb/ser-tcp.c
+++ b/gdb/ser-tcp.c
@@ -280,10 +280,10 @@ net_open (struct serial *scb, const char *name)
 
     len = sizeof (err);
     /* On Windows, the fourth parameter to getsockopt is a "char *";
-       on UNIX systems it is generally "void *".  The cast to "void *"
-       is OK everywhere, since in C "void *" can be implicitly
-       converted to any pointer type.  */
-    res = getsockopt (scb->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len);
+       on UNIX systems it is generally "void *".  The cast to "char *"
+       is OK everywhere, since in C++ any data pointer type can be
+       implicitly converted to "void *".  */
+    res = getsockopt (scb->fd, SOL_SOCKET, SO_ERROR, (char *) &err, &len);
     if (res < 0 || err)
       {
 	/* Maybe the target still isn't ready to accept the connection.  */
@@ -342,13 +342,17 @@ net_read_prim (struct serial *scb, size_t count)
   /* Need to cast to silence -Wpointer-sign on MinGW, as Winsock's
      'recv' takes 'char *' as second argument, while 'scb->buf' is
      'unsigned char *'.  */
-  return recv (scb->fd, (void *) scb->buf, count, 0);
+  return recv (scb->fd, (char *) scb->buf, count, 0);
 }
 
 int
 net_write_prim (struct serial *scb, const void *buf, size_t count)
 {
-  return send (scb->fd, buf, count, 0);
+  /* On Windows, the second parameter to send is a "const char *"; on
+     UNIX systems it is generally "const void *".  The cast to "const
+     char *" is OK everywhere, since in C++ any data pointer type can
+     be implicitly converted to "const void *".  */
+  return send (scb->fd, (const char *) buf, count, 0);
 }
 
 int


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