This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2.1] Use saturated arithmetic for overflow detection.


On Tue, 3 Dec 2013, Paul Eggert wrote:

> > +mul_s (size_t x, size_t y)
> 
> The implementation here is slow and complex.  It'd be better to use

Even for the normal case where one argument is constant?  (For the other 
case, it's based on the optimizations in calloc to avoid division in the 
common case where both arguments are small enough that the product can't 
possibly overflow, though that optimization is from 2002 so considerations 
may be different now; I don't know the typical speed of double-length 
multiplication.)

> There's no need for that comment.  On the other hand, with my pedantic
> hat on, you might want to mention that the above test assumes that
> INT_MAX < SIZE_MAX.  Perhaps put in a static assertion (doesn't
> glibc support _Static_assert yet? if not, just add a comment).

glibc supports being built with GCC 4.4 and later, and _Static_assert was 
added in 4.6, so using it would require increasing the minimum GCC version 
for building glibc.

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]