summaryrefslogtreecommitdiff
path: root/chapter14/src/main/java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-09-15 09:37:51 -0700
committerXmiliaH <45106915+XmiliaH@users.noreply.github.com>2024-09-15 18:44:01 +0200
commit25d855d2a9a0828826d07bde39d6dfe8c7110da6 (patch)
treea337e202e66b397fb9787fae107a939d2cc7ef34 /chapter14/src/main/java
parent301d9af0f8ca5397dd64c45ab5649df3f6944c5c (diff)
downloadSimple-25d855d2a9a0828826d07bde39d6dfe8c7110da6.tar.gz
Simple-25d855d2a9a0828826d07bde39d6dfe8c7110da6.zip
fix Minus wrapping MIN_LONG
Diffstat (limited to 'chapter14/src/main/java')
-rw-r--r--chapter14/src/main/java/com/seaofnodes/simple/node/MinusNode.java4
1 files changed, 3 insertions, 1 deletions
diff --git a/chapter14/src/main/java/com/seaofnodes/simple/node/MinusNode.java b/chapter14/src/main/java/com/seaofnodes/simple/node/MinusNode.java
index 8a2c9406..8ba45d26 100644
--- a/chapter14/src/main/java/com/seaofnodes/simple/node/MinusNode.java
+++ b/chapter14/src/main/java/com/seaofnodes/simple/node/MinusNode.java
@@ -22,7 +22,9 @@ public class MinusNode extends Node {
public Type compute() {
if( in(1)._type instanceof TypeInteger i0 ) {
if( i0.isHigh() ) return TypeInteger.TOP;
- return i0==TypeInteger.BOT ? TypeInteger.BOT : TypeInteger.make(-i0._max,-i0._min);
+ // Catch overflow wrapping on `-Long.MIN_VALUE`
+ if( i0 == TypeInteger.BOT || i0._min == Long.MIN_VALUE ) return TypeInteger.BOT;
+ return TypeInteger.make(-i0._max,-i0._min);
}
return TypeInteger.TOP.meet(in(1)._type);
}