This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Use saturated arithmetic for overflow detection.
- From: "Joseph S. Myers" <joseph at codesourcery dot com>
- To: OndÅej BÃlka <neleai at seznam dot cz>
- Cc: Paul Eggert <eggert at cs dot ucla dot edu>, <libc-alpha at sourceware dot org>
- Date: Wed, 30 Oct 2013 17:54:06 +0000
- Subject: Re: [PATCH] Use saturated arithmetic for overflow detection.
- Authentication-results: sourceware.org; auth=none
- References: <20131030174502 dot GA18107 at domone dot podge>
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