Skip to content

Commit dd4158b

Browse files
committed
Clip the overflowing value in CastToLongLossyNode instead of returning 0
1 parent da33164 commit dd4158b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/util/CastToJavaLongLossyNode.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public static CastToJavaLongLossyNode getUncached() {
6161

6262
@Specialization
6363
protected long toLong(PInt x) {
64-
return x.longValue();
64+
try {
65+
return x.longValueExact();
66+
} catch (ArithmeticException e) {
67+
if (x.isNegative()) {
68+
return Long.MIN_VALUE;
69+
} else {
70+
return Long.MAX_VALUE;
71+
}
72+
}
6573
}
6674
}

0 commit comments

Comments
 (0)