* [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt
@ 2013-03-05 9:51 Lei Li
2013-03-06 8:59 ` Markus Armbruster
2013-03-06 9:56 ` Stefan Hajnoczi
0 siblings, 2 replies; 7+ messages in thread
From: Lei Li @ 2013-03-05 9:51 UTC (permalink / raw)
To: qemu-devel; +Cc: stefanha, mdroh, 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 <lilei@linux.vnet.ibm.com>
---
util/osdep.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/util/osdep.c b/util/osdep.c
index c408261..ce472a9 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -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)
--
1.7.11.7
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt
2013-03-05 9:51 [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt Lei Li
@ 2013-03-06 8:59 ` Markus Armbruster
2013-03-06 13:09 ` Lei Li
2013-03-06 9:56 ` Stefan Hajnoczi
1 sibling, 1 reply; 7+ messages in thread
From: Markus Armbruster @ 2013-03-06 8:59 UTC (permalink / raw)
To: Lei Li; +Cc: stefanha, mdroh, qemu-devel
Lei Li <lilei@linux.vnet.ibm.com> writes:
> 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 <lilei@linux.vnet.ibm.com>
> ---
> util/osdep.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/util/osdep.c b/util/osdep.c
> index c408261..ce472a9 100644
> --- a/util/osdep.c
> +++ b/util/osdep.c
> @@ -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)
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 *.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt
2013-03-06 8:59 ` Markus Armbruster
@ 2013-03-06 13:09 ` Lei Li
0 siblings, 0 replies; 7+ messages in thread
From: Lei Li @ 2013-03-06 13:09 UTC (permalink / raw)
To: Markus Armbruster; +Cc: stefanha, mdroh, qemu-devel
On 03/06/2013 04:59 PM, Markus Armbruster wrote:
> Lei Li <lilei@linux.vnet.ibm.com> writes:
>
>> 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 <lilei@linux.vnet.ibm.com>
>> ---
>> util/osdep.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/util/osdep.c b/util/osdep.c
>> index c408261..ce472a9 100644
>> --- a/util/osdep.c
>> +++ b/util/osdep.c
>> @@ -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)
> 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.
--
Lei
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt
2013-03-05 9:51 [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt Lei Li
2013-03-06 8:59 ` Markus Armbruster
@ 2013-03-06 9:56 ` Stefan Hajnoczi
2013-03-06 13:07 ` Lei Li
1 sibling, 1 reply; 7+ messages in thread
From: Stefan Hajnoczi @ 2013-03-06 9:56 UTC (permalink / raw)
To: Lei Li; +Cc: mdroh, qemu-devel
On Tue, Mar 05, 2013 at 05:51:21PM +0800, Lei Li wrote:
> 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 <lilei@linux.vnet.ibm.com>
> ---
> util/osdep.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/util/osdep.c b/util/osdep.c
> index c408261..ce472a9 100644
> --- a/util/osdep.c
> +++ b/util/osdep.c
> @@ -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));
Please use qemu_setsockopt() instead of open-coding this.
Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt
2013-03-06 9:56 ` Stefan Hajnoczi
@ 2013-03-06 13:07 ` Lei Li
2013-03-06 13:16 ` Stefan Hajnoczi
0 siblings, 1 reply; 7+ messages in thread
From: Lei Li @ 2013-03-06 13:07 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: mdroh, qemu-devel
On 03/06/2013 05:56 PM, Stefan Hajnoczi wrote:
> On Tue, Mar 05, 2013 at 05:51:21PM +0800, Lei Li wrote:
>> 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 <lilei@linux.vnet.ibm.com>
>> ---
>> util/osdep.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/util/osdep.c b/util/osdep.c
>> index c408261..ce472a9 100644
>> --- a/util/osdep.c
>> +++ b/util/osdep.c
>> @@ -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));
> Please use qemu_setsockopt() instead of open-coding this.
>
> 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
--
Lei
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt
2013-03-06 13:07 ` Lei Li
@ 2013-03-06 13:16 ` Stefan Hajnoczi
2013-03-06 13:25 ` Lei Li
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Hajnoczi @ 2013-03-06 13:16 UTC (permalink / raw)
To: Lei Li; +Cc: mdroh, qemu-devel, Markus Armbruster
On Wed, Mar 06, 2013 at 09:07:25PM +0800, Lei Li wrote:
> On 03/06/2013 05:56 PM, Stefan Hajnoczi wrote:
> >On Tue, Mar 05, 2013 at 05:51:21PM +0800, Lei Li wrote:
> >>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 <lilei@linux.vnet.ibm.com>
> >>---
> >> util/osdep.c | 4 ++--
> >> 1 file changed, 2 insertions(+), 2 deletions(-)
> >>
> >>diff --git a/util/osdep.c b/util/osdep.c
> >>index c408261..ce472a9 100644
> >>--- a/util/osdep.c
> >>+++ b/util/osdep.c
> >>@@ -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));
> >Please use qemu_setsockopt() instead of open-coding this.
> >
> >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
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt
2013-03-06 13:16 ` Stefan Hajnoczi
@ 2013-03-06 13:25 ` Lei Li
0 siblings, 0 replies; 7+ messages in thread
From: Lei Li @ 2013-03-06 13:25 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: mdroh, qemu-devel, Markus Armbruster
On 03/06/2013 09:16 PM, Stefan Hajnoczi wrote:
> On Wed, Mar 06, 2013 at 09:07:25PM +0800, Lei Li wrote:
>> On 03/06/2013 05:56 PM, Stefan Hajnoczi wrote:
>>> On Tue, Mar 05, 2013 at 05:51:21PM +0800, Lei Li wrote:
>>>> 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 <lilei@linux.vnet.ibm.com>
>>>> ---
>>>> util/osdep.c | 4 ++--
>>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/util/osdep.c b/util/osdep.c
>>>> index c408261..ce472a9 100644
>>>> --- a/util/osdep.c
>>>> +++ b/util/osdep.c
>>>> @@ -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));
>>> Please use qemu_setsockopt() instead of open-coding this.
>>>
>>> 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
> 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
Sorry, I understand it just now... :-[
Sure, thanks!
--
Lei
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-03-06 13:26 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-05 9:51 [Qemu-devel] [PATCH] osdep: pass const char pointer to setsockopt Lei Li
2013-03-06 8:59 ` Markus Armbruster
2013-03-06 13:09 ` Lei Li
2013-03-06 9:56 ` Stefan Hajnoczi
2013-03-06 13:07 ` Lei Li
2013-03-06 13:16 ` Stefan Hajnoczi
2013-03-06 13:25 ` Lei Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).