bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: undefined behavior in hol_append()


From: Eric Blake
Subject: Re: undefined behavior in hol_append()
Date: Mon, 28 Nov 2011 17:06:07 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:8.0) Gecko/20111115 Thunderbird/8.0

On 11/28/2011 04:39 PM, Bruno Haible wrote:
> Hi Matthew,
> 
>> e->short_options += (short_options - hol->short_options);
>>
>> subtracts two pointers that do not point to the same memory object.
>> Something like:
>>
>> e->short_options = short_options + (e->short_options - hol->short_options);
>>
>> does the intended operation with legal pointer arithmetic.
> 
> Thanks for the suggestion.
> 
> However, I find the existing code easier to understand than the one you
> propose. Therefore, to understand the possible impact, a question:
> 
> Do you know of any platforms where sizeof (ptrdiff_t) < sizeof (void *) ?

In current practice, no, I don't.  But in theory, it is possible to have
a 64-bit void* but only a 32-bit ptrdiff_t, on a platform where the
maximum compiled object is only 4GiB (since ptrdiff_t need only
represent the difference between offsets within an object, and not a
full pointer).  And as an actual example, in the old days of x86 segment
programming (thankfully now long gone), it was possible to have 32-bit
pointers but only 16-bit ptrdiff_t to represent the max size of an
object that resides in the current segment overlay.

http://lkml.indiana.edu/hypermail/linux/kernel/9902.2/0238.html

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]