[java-dfa] Remove incorrect range-narrowing in ModRange.plus

If we overflow and myMod is not a power of 2, we cannot rotate remainders: overflowed subrange may have different remainders. E.g. floorMod(Integer.MAX_VALUE, 6) = 1 but floorMod(Integer.MAX_VALUE+1, 6) = 4, not 2.
Better algorithm is possible if we initially split our range at overflow point, then perform addition separately but for now let's just produce a correct result
Fixes EA-257681 - IAE: LongRangeSet$Range.<init>

GitOrigin-RevId: 45a3a870ae238800386b6ce739694f8f847e6340
This commit is contained in:
Tagir Valeev
2021-02-25 06:26:23 +00:00
committed by intellij-monorepo-bot
parent 01f2002956
commit 14d6ae1b03
2 changed files with 11 additions and 5 deletions
@@ -1867,11 +1867,7 @@ public abstract class LongRangeSet {
plus = modRange(ranges[i], ranges[i + 1], myMod, bits);
}
else {
long min = ranges[i];
while (!isSet(bits, remainder(min, myMod))) min++;
long max = ranges[i + 1];
while (!isSet(bits, remainder(max, myMod))) max--;
plus = range(min, max);
plus = range(ranges[i], ranges[i + 1]);
}
result = result.unite(plus);
}
@@ -34,4 +34,14 @@ public class LongRangeMod {
i++;
}
}
// EA-257681 - IAE: LongRangeSet$Range.<init>
void test(int a, int b) {
if (a % 2 == 0)
b += a / 2;
else if (a % 3 == 0)
b += a / 3;
else
a++;
}
}