#1245: src/pmc/integer.pmc: Check overflow for -maxint in absolute()
---------------------+------------------------------------------------------
Reporter: jkeenan | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: core | Version: 1.7.0
Severity: medium | Keywords:
Lang: | Patch:
Platform: |
---------------------+------------------------------------------------------
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."''
--
Ticket URL: <https://trac.parrot.org/parrot/ticket/1245>
Parrot <https://trac.parrot.org/parrot/>
Parrot Development
_______________________________________________
parrot-tickets mailing list
[email protected]
http://lists.parrot.org/mailman/listinfo/parrot-tickets