From: Kevin Wolf <kwolf@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] Fix conversions from pointer to int and vice versa
Date: Thu, 24 Feb 2011 10:17:10 +0100 [thread overview]
Message-ID: <4D662216.2050207@redhat.com> (raw)
In-Reply-To: <m34o7thp8f.fsf@blackfin.pond.sub.org>
Am 24.02.2011 08:21, schrieb Markus Armbruster:
> Stefan Weil <weil@mail.berlios.de> writes:
>
>> Here the int values fds[0], sigfd, s, sock and fd are converted
>> to void pointers which are later converted back to an int value.
>>
>> These conversions should always use intptr_t instead of unsigned long.
>>
>> They are needed for environments where sizeof(long) != sizeof(void *).
>
> To be precise: when you want to cast a pointer to a signed integer type
> and back without loss, intptr_t is the signed integer type to use.
>
> But here we're dealing with the opposite case: cast int to pointer and
> back.
>
>> Signed-off-by: Stefan Weil <weil@mail.berlios.de>
>> ---
>> cpus.c | 8 ++++----
>> migration-tcp.c | 4 ++--
>> migration-unix.c | 4 ++--
>> qemu-char.c | 4 ++--
>> 4 files changed, 10 insertions(+), 10 deletions(-)
>>
>> diff --git a/cpus.c b/cpus.c
>> index 0f33945..3c4e1b8 100644
>> --- a/cpus.c
>> +++ b/cpus.c
>> @@ -267,7 +267,7 @@ static void qemu_event_increment(void)
>>
>> static void qemu_event_read(void *opaque)
>> {
>> - int fd = (unsigned long)opaque;
>> + int fd = (intptr_t)opaque;
>> ssize_t len;
>> char buffer[512];
>>
>
> Why can't you cast straight to int?
You would get warnings about a pointer being cast to an integer of
different size (the behaviour is undefined if the integer is too small).
I think you might also get a warning for the opposite direction.
Kevin
next prev parent reply other threads:[~2011-02-24 9:15 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-23 18:09 [Qemu-devel] [PATCH] Fix conversions from pointer to int and vice versa Stefan Weil
2011-02-23 20:03 ` [Qemu-devel] " Juan Quintela
2011-02-24 7:21 ` [Qemu-devel] " Markus Armbruster
2011-02-24 7:59 ` [Qemu-devel] " Paolo Bonzini
2011-02-24 9:17 ` Kevin Wolf [this message]
2011-02-24 10:11 ` [Qemu-devel] " Markus Armbruster
2011-02-24 19:57 ` Stefan Weil
2011-03-20 12:07 ` Stefan Weil
2011-03-20 21:50 ` Blue Swirl
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=4D662216.2050207@redhat.com \
--to=kwolf@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=armbru@redhat.com \
--cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.