[PATCH] Improve check against integer wraparound in hcreate_r [BZ #18240]

Paul Eggert eggert@cs.ucla.edu
Tue Jan 26 00:06:00 GMT 2016


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hcreate.diff
Type: text/x-patch
Size: 1598 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20160126/0092d891/attachment.bin>


More information about the Libc-alpha mailing list