Skip to content

Commit 8600510

Browse files
committed
Correct handling for Integer.MIN_VALUE in LazyIntRope
1 parent d4ab025 commit 8600510

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/main/java/org/truffleruby/core/rope/LazyIntRope.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ protected LazyIntRope(int value, Encoding encoding, int length) {
4848
private static int length(int value) {
4949
final int sign;
5050
if (CompilerDirectives.injectBranchProbability(CompilerDirectives.UNLIKELY_PROBABILITY, value < 0)) {
51+
// We can't represent -Integer.MIN_VALUE (it results in Integer.MIN_VALUE), so we need to handle it explicitly
52+
if (CompilerDirectives
53+
.injectBranchProbability(CompilerDirectives.SLOWPATH_PROBABILITY, value == Integer.MIN_VALUE)) {
54+
return 11;
55+
}
56+
5157
sign = 1;
5258
value = -value;
5359
} else {

0 commit comments

Comments
 (0)