id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc	lang	patch	platform
1245	src/pmc/integer.pmc:  Check overflow for -maxint in absolute()	jkeenan	Paul C. Anagnostopoulos	"This ticket moves to the Trac system discussion of an issue previously found in RT at [http://rt.perl.org/rt3/Ticket/Display.html?id=46635 RT #46635].

Here is the relevant section of ''src/pmc/integer.pmc'':
{{{
1260     VTABLE PMC *absolute(PMC *dest) {
1261         const INTVAL a = abs(SELF.get_integer());
1262 
1263         /* RT #46635 overflow for -maxint */
1264         dest = pmc_new(INTERP, VTABLE_type(INTERP, SELF));
1265 
1266         VTABLE_set_integer_native(INTERP, dest, a);
1267         return dest;
1268 
1269     }
}}}
In RT, Paul Cochrane commented: ''""I think [this] means that before setting the integer value we need to check here for overflow of -maxint (or at least numbers which go over the maximum integer value allowed on the current platform, or something like that).""''

Discussion among whiteknight, cotto and NotFound followed.  The last comment from NotFound was:

''""The current implementation is wrong. abs takes and returns an int, but parrot INTVAL is not guaranteed to be int.''

''""Even worse, 'Trying to take the absolute value of the most negative integer is not defined' (from the linux man page, and the C standard if I remember well). So is not granted that we can take decisions based on the result of abs, must be done before.''

''""To obtain a safe implementation, abs must be avoided.""''
"	bug	closed	normal		core	1.7.0	medium	duplicate		whiteknight cotto Notfound			
