Clojure

GC Issue 28: Substraction sometimes yields wrong result due to IntegerOps.Negate overflow (with patch

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Reported by olov.lassus, Jan 02, 2009
Negating Integer.MIN_VALUE overflows but should return a BigInteger.  
It also affects binary subtraction since Clojure implements it using  
negation and addition. The overflow occurs silently without throwing  
an exception.

These examples trigger the flaw:

user=> (- -2147483648)
-2147483648

user=> (- -1 -2147483648)
-2147483649


The attached patch apply cleanly against trunk r1195. Same examples after
applying it:

user=> (- -2147483648)
2147483648

user=> (- -1 -2147483648)
2147483647

 detect_negate_overflow.patch
507 bytes Download
Comment 1 by richhickey, Jan 07, 2009
fixed in svn 1203
Status: Fixed

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: