[PATCH] Improve check against integer wraparound in hcreate_r [BZ #18240]
Florian Weimer
fweimer@redhat.com
Wed Jan 27 16:52:00 GMT 2016
On 01/26/2016 01:06 AM, Paul Eggert wrote:
> On 01/25/2016 12:09 PM, Florian Weimer wrote:
>> - while (div * div < number && number % div != 0)
>> + while (div * (unsigned long long) div < number && number % div != 0)
>
> Good catch. But better yet, get rid of the '*' so that we needn't worry
> about whether the multiplication overflows. On typical platforms the
> divide instruction that the '%' is already doing will give us the
> information we need, so this is faster anyway. Something like the
> attached (untested) patch.
I looked at the generated assembly on x86-64, and confirm that there's
just one division. Rest looks good to me, too.
I'm attaching a real patch which also includes the test I wrote (it
still passes, but it really doesn't do anything).
Florian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Improve-check-against-integer-wraparound-in-hcreate_.patch
Type: text/x-patch
Size: 4550 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20160127/a771c6e1/attachment.bin>
More information about the Libc-alpha
mailing list