From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=60789 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PD1z0-0003U1-2r for qemu-devel@nongnu.org; Mon, 01 Nov 2010 17:32:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PD1yy-0006DG-EE for qemu-devel@nongnu.org; Mon, 01 Nov 2010 17:32:01 -0400 Received: from moutng.kundenserver.de ([212.227.126.186]:50838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PD1yy-0006Ci-0t for qemu-devel@nongnu.org; Mon, 01 Nov 2010 17:32:00 -0400 Message-ID: <4CCF31CC.2070804@mail.berlios.de> Date: Mon, 01 Nov 2010 22:31:56 +0100 From: Stefan Weil MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 02/40] elf: Add notes implementation References: <1288623713-28062-1-git-send-email-agraf@suse.de> <1288623713-28062-3-git-send-email-agraf@suse.de> <4CCF0A13.1060202@mail.berlios.de> <4CCF20BE.8010205@mail.berlios.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: Blue Swirl , Michael Matz , qemu-devel Developers , Gerd Hoffmann Am 01.11.2010 22:17, schrieb Alexander Graf: > > On 01.11.2010, at 16:19, Stefan Weil wrote: > >> Am 01.11.2010 20:51, schrieb Alexander Graf: >>> On 01.11.2010, at 14:42, Stefan Weil wrote: >>> >>> >>>> Am 01.11.2010 19:29, schrieb Blue Swirl: >>>> >>>>> On Mon, Nov 1, 2010 at 3:01 PM, Alexander Graf wrote: >>>>> >>>>> >>>>>> --- >>>>>> hw/elf_ops.h | 61 >>>>>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- >>>>>> hw/loader.c | 7 ++++++ >>>>>> hw/loader.h | 3 ++ >>>>>> 3 files changed, 70 insertions(+), 1 deletions(-) >>>>>> >>>>>> diff --git a/hw/elf_ops.h b/hw/elf_ops.h >>>>>> index 8b63dfc..645d058 100644 >>>>>> --- a/hw/elf_ops.h >>>>>> +++ b/hw/elf_ops.h >>>>>> @@ -189,6 +189,44 @@ static int glue(load_symbols, SZ)(struct >>>>>> elfhdr *ehdr, int fd, int must_swab, >>>>>> return -1; >>>>>> } >>>>>> >>>>>> +static void glue(elf_read_notes, SZ)(uint8_t *data, int data_len, >>>>>> + ElfHandlers *handlers, int must_swab) >>>>>> +{ >>>>>> + uint8_t *p = data; >>>>>> + >>>>>> + while ((ulong)&p[3]< (ulong)&data[data_len]) { >>>>>> >>>>>> >>>>> Please use 'unsigned long'. >>>>> >>>>> >>>> Why is a type cast used here? I see no reason for it. >>>> >>> Pointers can't be compared, you have to cast them to values first. >>> >>> >>> Alex >>> >> >> No. Pointers of same type which are not void pointers can be compared. >> >> There is even a data type ptrdiff_t, so you can also compare their >> difference with zero. > > Let's ask someone who definitely knows :). > > Michael, is code like > > char *x = a, *y = b; > if (x < y) { > ... > } > > valid? Or do I first have to cast x and y to unsigned longs or uintptr_t? > > > Alex > Hopefully C did not change for code like this during the last 20 years. Then your code is always valid, but will only return useful results if both a and b are derived from the same base pointer (plus an individual offset): char *base = any_value; a = base + offset_a; b = base + offset_b; Then x - y = a - b = (ptrdiff_t)(offset_a - offset_b) / (sizeof(*x); and (x < y) == (a < b) == (offset_a < offset_b); Regards, Stefan