From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=50099 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PsVWM-0007VH-La for qemu-devel@nongnu.org; Thu, 24 Feb 2011 02:21:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PsVWL-000144-6y for qemu-devel@nongnu.org; Thu, 24 Feb 2011 02:21:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:28226) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PsVWK-00013v-Sf for qemu-devel@nongnu.org; Thu, 24 Feb 2011 02:21:53 -0500 From: Markus Armbruster Subject: Re: [Qemu-devel] [PATCH] Fix conversions from pointer to int and vice versa References: <1298484556-5517-1-git-send-email-weil@mail.berlios.de> Date: Thu, 24 Feb 2011 08:21:36 +0100 In-Reply-To: <1298484556-5517-1-git-send-email-weil@mail.berlios.de> (Stefan Weil's message of "Wed, 23 Feb 2011 19:09:16 +0100") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Stefan Weil Cc: Anthony Liguori , qemu-devel@nongnu.org Stefan Weil 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 > --- > 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? > @@ -295,7 +295,7 @@ static int qemu_event_init(void) > goto fail; > } > qemu_set_fd_handler2(fds[0], NULL, qemu_event_read, NULL, > - (void *)(unsigned long)fds[0]); > + (void *)(intptr_t)fds[0]); > > io_thread_fd = fds[1]; > return 0; Why can't you cast straight to void *? [More of the same snipped...]