PATCH: Bad signed int to long long conversion

Vincent Lefevre vincent at vinc17.net
Thu Dec 1 09:30:17 CET 2011


On 2011-11-30 17:53:39 -0800, H.J. Lu wrote:
> According to
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50066
> 
> vl = (mp_limb_t) (unsigned long int) (val >= 0 ? val : -val);
> 
> is undefined when val is LONG_MIN.  The enclosed patch
> fixes it.

FYI, MPFR has the following macro concerning this:

/* Safe absolute value (to avoid possible integer overflow) */
/* type is the target (unsigned) type */
#define SAFE_ABS(type,x) ((x) >= 0 ? (type)(x) : -(type)(x))

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)


More information about the gmp-bugs mailing list