mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
take absolute value of a remainder, not a remainder of an absolute value
`Math.abs(INT_MIN) == INT_MIN` as a result, `Math.abs(x) % 10` might return negative value.
This commit is contained in:
+5
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -76,6 +77,10 @@ public class LightRainbowHighlightingTest extends LightCodeInsightFixtureTestCas
|
||||
"}", true, true);
|
||||
}
|
||||
|
||||
public void testBadStringHashValue() {
|
||||
int color = UsedColors.getOrAddColorIndex(new UserDataHolderBase(), "JHZaWC", 5);
|
||||
assertEquals(3, color);
|
||||
}
|
||||
|
||||
void checkRainbow(@NotNull String code, boolean isRainbowOn, boolean withColor) throws Exception {
|
||||
myFixture.testRainbow(
|
||||
|
||||
@@ -97,7 +97,7 @@ public class UsedColors {
|
||||
}
|
||||
|
||||
private static int hashColor(@NotNull String name, int colorsCount) {
|
||||
return Math.abs(StringHash.murmur(name, 0x55AA)) % colorsCount;
|
||||
return Math.abs(StringHash.murmur(name, 0x55AA) % colorsCount);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
|
||||
+1
-1
@@ -180,7 +180,7 @@ public class StatisticsManagerImpl extends StatisticsManager {
|
||||
}
|
||||
|
||||
private static int getUnitNumber(String key1) {
|
||||
return Math.abs(key1.hashCode()) % UNIT_COUNT;
|
||||
return Math.abs(key1.hashCode() % UNIT_COUNT);
|
||||
}
|
||||
|
||||
private static boolean createStoreFolder(){
|
||||
|
||||
@@ -69,4 +69,7 @@ public class StatisticsManagerTest extends LightPlatformTestCase {
|
||||
assertEquals(Integer.MAX_VALUE, new StatisticsInfo("anotherContext", "value0").getLastUseRecency());
|
||||
}
|
||||
|
||||
public void testBadHashValue() {
|
||||
StatisticsManager.getInstance().getUseCount(new StatisticsInfo("MVFOFVB", ""));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,14 @@ public class BloomFilterBase {
|
||||
|
||||
protected final void addIt(int prime, int prime2) {
|
||||
for(int i = 0; i < myHashFunctionCount; ++i) {
|
||||
int abs = Math.abs(i * prime + prime2 * (myHashFunctionCount - i)) % myBitsCount;
|
||||
int abs = Math.abs((i * prime + prime2 * (myHashFunctionCount - i)) % myBitsCount);
|
||||
myElementsSet[abs >> BITS_PER_ELEMENT] |= (1L << abs);
|
||||
}
|
||||
}
|
||||
|
||||
protected final boolean maybeContains(int prime, int prime2) {
|
||||
for(int i = 0; i < myHashFunctionCount; ++i) {
|
||||
int abs = Math.abs(i * prime + prime2 * (myHashFunctionCount - i)) % myBitsCount;
|
||||
int abs = Math.abs((i * prime + prime2 * (myHashFunctionCount - i)) % myBitsCount);
|
||||
if ((myElementsSet[abs >> BITS_PER_ELEMENT] & (1L << abs)) == 0) return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class DefaultColorGenerator implements ColorGenerator {
|
||||
}
|
||||
|
||||
private static int rangeFix(int n) {
|
||||
return Math.abs(n) % 100 + 70;
|
||||
return Math.abs(n % 100) + 70;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user