[PATCH] Use saturated arithmetic for overflow detection.
Joseph S. Myers
joseph@codesourcery.com
Wed Oct 30 17:54:00 GMT 2013
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
More information about the Libc-alpha
mailing list