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] Use saturated arithmetic for overflow detection.


On Wed, 30 Oct 2013, Ondrej Bilka wrote:

> 	* bits/saturated.h: New file.

The bits/*.h naming convention should only be used for installed headers, 
not internal headers like this one.  See bug 14912.

> +#define MUL_S(___x, ___y)({ \

Missing space between ')' and '('.

> +  size_t __x = (___x), __y = (___y);                    \
> +  __builtin_constant_p (__x) 				\
> +  ? (__y <= SIZE_MAX / __x ? __x * __y : SIZE_MAX)	\
> +  : (__x <= SIZE_MAX / __y ? __x * __y : SIZE_MAX);	\

This would divide by 0 if an argument is 0.

No need for __ in macro paramater names, as each macro has its own 
namespace for parameter names and they can't interfere with any use of 
those names outside the token sequence in the #define directive.  So just 
call the parameters x and y.  (The variables __x and __y used within the 
macros *do* need the underscores.)

-- 
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]