osdep: pass const char pointer to setsockopt
PATCH 1/1 osdep: pass const char pointer to setsockopt
Pass the right type for setsockopt(), and this will also fix the compiler warning when cross build for qemu-ga.exe:
util/osdep.c: In function 'socket_set_nodelay':util/osdep.c:69:5: warning: passing argument 4 of 'setsockopt' from
incompatible pointer type [enabled by default]
In file included from /home/lei/qemu_b/include/sysemu/os-win32.h:30:0,
from /home/lei/qemu_b/include/qemu-common.h:46,
from util/osdep.c:48:/usr/i686-w64-mingw32/sys-root/mingw/include/winsock2.h:990:63: note:
expected 'const char *' but argument is of type 'int *'
--- util/osdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
util/osdep.c +2 -2
@@ -57,7 +57,7 @@ static const char *qemu_version = QEMU_VERSION;int socket_set_cork (int fd,int v) {#if defined(SOL_TCP ) && defined(TCP_CORK ) -return setsockopt (fd,SOL_TCP ,TCP_CORK , &v,sizeof (v)); +return setsockopt (fd,SOL_TCP ,TCP_CORK , (char *)&v,sizeof (v));#else return 0 ;#endif
@@ -66,7 +66,7 @@ int socket_set_cork(int fd, int v)int socket_set_nodelay (int fd) {int v =1 ; -return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , &v,sizeof (v)); +return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , (char *)&v,sizeof (v)); }int qemu_madvise (void *addr,size_t len,int advice)
Signature · 1 line
1.7.11.7
Quoted 31 lines · Lei Li
Pass the right type for
setsockopt(), and this will also fix the compiler warning when cross build for qemu-ga.exe:
util/osdep.c: In function 'socket_set_nodelay':util/osdep.c:69:5: warning: passing argument 4 of 'setsockopt' from
incompatible pointer type [enabled by default]
In file included from/home/lei/qemu_b/include/sysemu/os-win32.h:30:0,from /home/lei/qemu_b/include/qemu-common.h:46, from util/osdep.c:48:
/usr/i686-w64-mingw32/sys-root/mingw/include/winsock2.h:990:63: note:
expected 'const char *' but argument is of type 'int *'Signed-off-by Lei Li <[email protected]>--- util/osdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)util/osdep.c +1
-1@@ -57,7 +57,7 @@ static const char *qemu_version = QEMU_VERSION;int socket_set_cork (int fd,int v) {#if defined(SOL_TCP ) && defined(TCP_CORK ) -return setsockopt (fd,SOL_TCP ,TCP_CORK , &v,sizeof (v)); +return setsockopt (fd,SOL_TCP ,TCP_CORK , (char *)&v,sizeof (v));#else return 0 ;#endif
util/osdep.c int socket_set_cork(int fd, int v) · line 72
Quoted 8 lines
util/osdep.c +1
-1@@ -66,7 +66,7 @@ int socket_set_cork(int fd, int v)int socket_set_nodelay (int fd) {int v =1 ; -return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , &v,sizeof (v)); +return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , (char *)&v,sizeof (v)); }int qemu_madvise (void *addr,size_t len,int advice)
Please cast to void * instead, for clarity.
The parameter is void * in modern setsockopt(). No cast required. Winsock appears to be stuck in the stone age: it takes char *.
Quoted 40 lines · Markus Armbruster
Quoted 38 lines · Lei Li
Pass the right type for
setsockopt(), and this will also fix the compiler warning when cross build for qemu-ga.exe:
util/osdep.c: In function 'socket_set_nodelay':util/osdep.c:69:5: warning: passing argument 4 of 'setsockopt' from
incompatible pointer type [enabled by default]
In file included from/home/lei/qemu_b/include/sysemu/os-win32.h:30:0,from /home/lei/qemu_b/include/qemu-common.h:46, from util/osdep.c:48:
/usr/i686-w64-mingw32/sys-root/mingw/include/winsock2.h:990:63: note:
expected 'const char *' but argument is of type 'int *'Signed-off-by Lei Li <[email protected]>--- util/osdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)util/osdep.c +2
-2@@ -57,7 +57,7 @@ static const char *qemu_version = QEMU_VERSION;int socket_set_cork (int fd,int v) {#if defined(SOL_TCP ) && defined(TCP_CORK ) -return setsockopt (fd,SOL_TCP ,TCP_CORK , &v,sizeof (v)); +return setsockopt (fd,SOL_TCP ,TCP_CORK , (char *)&v,sizeof (v));#else return 0 ;#endif @@ -66,7 +66,7 @@ int socket_set_cork(int fd, int v)int socket_set_nodelay (int fd) {int v =1 ; -return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , &v,sizeof (v)); +return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , (char *)&v,sizeof (v)); }
Quoted 5 lines
util/osdep.c int socket_set_cork(int fd, int v) · line 72
Quoted 1 line
util/osdep.c +0
-0int qemu_madvise (void *addr,size_t len,int advice)Please cast to void * instead, for clarity.
The parameter is void * in modern
setsockopt(). No cast required. Winsock appears to be stuck in the stone age: it takes char *.
Got it, thanks.
Signature · 1 line
Lei
Quoted 31 lines · Lei Li
Pass the right type for
setsockopt(), and this will also fix the compiler warning when cross build for qemu-ga.exe:
util/osdep.c: In function 'socket_set_nodelay':util/osdep.c:69:5: warning: passing argument 4 of 'setsockopt' from
incompatible pointer type [enabled by default]
In file included from/home/lei/qemu_b/include/sysemu/os-win32.h:30:0,from /home/lei/qemu_b/include/qemu-common.h:46, from util/osdep.c:48:
/usr/i686-w64-mingw32/sys-root/mingw/include/winsock2.h:990:63: note:
expected 'const char *' but argument is of type 'int *'Signed-off-by Lei Li <[email protected]>--- util/osdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)util/osdep.c +1
-1@@ -57,7 +57,7 @@ static const char *qemu_version = QEMU_VERSION;int socket_set_cork (int fd,int v) {#if defined(SOL_TCP ) && defined(TCP_CORK ) -return setsockopt (fd,SOL_TCP ,TCP_CORK , &v,sizeof (v)); +return setsockopt (fd,SOL_TCP ,TCP_CORK , (char *)&v,sizeof (v));#else return 0 ;#endif
util/osdep.c int socket_set_cork(int fd, int v) · line 69
Quoted 5 lines
util/osdep.c +1
-1@@ -66,7 +66,7 @@ int socket_set_cork(int fd, int v)int socket_set_nodelay (int fd) {int v =1 ; -return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , &v,sizeof (v)); +return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , (char *)&v,sizeof (v));
Please use qemu_setsockopt() instead of open-coding this.
Stefan
Quoted 39 lines · Stefan Hajnoczi
Quoted 31 lines · Lei Li
Pass the right type for
setsockopt(), and this will also fix the compiler warning when cross build for qemu-ga.exe:
util/osdep.c: In function 'socket_set_nodelay':util/osdep.c:69:5: warning: passing argument 4 of 'setsockopt' from
incompatible pointer type [enabled by default]
In file included from/home/lei/qemu_b/include/sysemu/os-win32.h:30:0,from /home/lei/qemu_b/include/qemu-common.h:46, from util/osdep.c:48:
/usr/i686-w64-mingw32/sys-root/mingw/include/winsock2.h:990:63: note:
expected 'const char *' but argument is of type 'int *'Signed-off-by Lei Li <[email protected]>--- util/osdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)util/osdep.c +1
-1@@ -57,7 +57,7 @@ static const char *qemu_version = QEMU_VERSION;int socket_set_cork (int fd,int v) {#if defined(SOL_TCP ) && defined(TCP_CORK ) -return setsockopt (fd,SOL_TCP ,TCP_CORK , &v,sizeof (v)); +return setsockopt (fd,SOL_TCP ,TCP_CORK , (char *)&v,sizeof (v));#else return 0 ;#endif util/osdep.c int socket_set_cork(int fd, int v) · line 69
Quoted 5 lines
util/osdep.c +1
-1@@ -66,7 +66,7 @@ int socket_set_cork(int fd, int v)int socket_set_nodelay (int fd) {int v =1 ; -return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , &v,sizeof (v)); +return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , (char *)&v,sizeof (v));Please use
qemu_setsockopt()instead of open-coding this.
Quoted 2 lines
Stefan
Hi Stefan,
This compiler warning just shows up without any hacking when cross build qemu-ga for windows by:
./configure --enable-guest-agent --cross-prefix=i686-w64-mingw32- make qemu-ga.exe
Signature · 1 line
Lei
Quoted 42 lines · Lei Li
Quoted 39 lines · Stefan Hajnoczi
Quoted 31 lines · Lei Li
Pass the right type for
setsockopt(), and this will also fix the compiler warning when cross build for qemu-ga.exe:
util/osdep.c: In function 'socket_set_nodelay':util/osdep.c:69:5: warning: passing argument 4 of 'setsockopt' from
incompatible pointer type [enabled by default]
In file included from/home/lei/qemu_b/include/sysemu/os-win32.h:30:0,from /home/lei/qemu_b/include/qemu-common.h:46, from util/osdep.c:48:
/usr/i686-w64-mingw32/sys-root/mingw/include/winsock2.h:990:63: note:
expected 'const char *' but argument is of type 'int *'Signed-off-by Lei Li <[email protected]>--- util/osdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)util/osdep.c +1
-1@@ -57,7 +57,7 @@ static const char *qemu_version = QEMU_VERSION;int socket_set_cork (int fd,int v) {#if defined(SOL_TCP ) && defined(TCP_CORK ) -return setsockopt (fd,SOL_TCP ,TCP_CORK , &v,sizeof (v)); +return setsockopt (fd,SOL_TCP ,TCP_CORK , (char *)&v,sizeof (v));#else return 0 ;#endif util/osdep.c int socket_set_cork(int fd, int v) · line 69
Quoted 5 lines
util/osdep.c +1
-1@@ -66,7 +66,7 @@ int socket_set_cork(int fd, int v)int socket_set_nodelay (int fd) {int v =1 ; -return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , &v,sizeof (v)); +return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , (char *)&v,sizeof (v));Please use
qemu_setsockopt()instead of open-coding this.Quoted 2 lines
Stefan
Quoted 7 lines
Hi Stefan,
This compiler warning just shows up without any hacking when cross build qemu-ga for windows by:
./configure --enable-guest-agent --cross-prefix=i686-w64-mingw32- make qemu-ga.exe
I understand you didn't introduce the bug and noticed it when compiling for Windows.
The correct fix is still to use qemu_setsockopt() which was added in order to solve this portability problem.
You don't need any casts if you use qemu_setsockopt().
Stefan
Quoted 53 lines · Stefan Hajnoczi
Quoted 42 lines · Lei Li
Quoted 39 lines · Stefan Hajnoczi
Quoted 31 lines · Lei Li
Pass the right type for
setsockopt(), and this will also fix the compiler warning when cross build for qemu-ga.exe:
util/osdep.c: In function 'socket_set_nodelay':util/osdep.c:69:5: warning: passing argument 4 of 'setsockopt' from
incompatible pointer type [enabled by default]
In file included from/home/lei/qemu_b/include/sysemu/os-win32.h:30:0,from /home/lei/qemu_b/include/qemu-common.h:46, from util/osdep.c:48:
/usr/i686-w64-mingw32/sys-root/mingw/include/winsock2.h:990:63: note:
expected 'const char *' but argument is of type 'int *'Signed-off-by Lei Li <[email protected]>--- util/osdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)util/osdep.c +1
-1@@ -57,7 +57,7 @@ static const char *qemu_version = QEMU_VERSION;int socket_set_cork (int fd,int v) {#if defined(SOL_TCP ) && defined(TCP_CORK ) -return setsockopt (fd,SOL_TCP ,TCP_CORK , &v,sizeof (v)); +return setsockopt (fd,SOL_TCP ,TCP_CORK , (char *)&v,sizeof (v));#else return 0 ;#endif util/osdep.c int socket_set_cork(int fd, int v) · line 69
Quoted 5 lines
util/osdep.c +1
-1@@ -66,7 +66,7 @@ int socket_set_cork(int fd, int v)int socket_set_nodelay (int fd) {int v =1 ; -return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , &v,sizeof (v)); +return setsockopt (fd,IPPROTO_TCP ,TCP_NODELAY , (char *)&v,sizeof (v));Please use
qemu_setsockopt()instead of open-coding this.Quoted 2 lines
Stefan
Quoted 7 lines
Hi Stefan,
This compiler warning just shows up without any hacking when cross build qemu-ga for windows by:
./configure --enable-guest-agent --cross-prefix=i686-w64-mingw32- make qemu-ga.exe
I understand you didn't introduce the bug and noticed it when compiling for Windows.
Quoted 6 lines
The correct fix is still to use
qemu_setsockopt()which was added in order to solve this portability problem.You don't need any casts if you use
qemu_setsockopt().Stefan
Sorry, I understand it just now... :-[
Sure, thanks!
Signature · 1 line
Lei