From 7411dda919ba903b1c1e21fd66ee83a62a098e07 Mon Sep 17 00:00:00 2001 From: Teng Zhang Date: Sat, 21 Sep 2024 16:44:04 +0800 Subject: [PATCH] Fix incorrect result when an empty bitset intersects with itself --- src/main/java/pascal/taie/util/collection/RegularBitSet.java | 3 +++ src/main/java/pascal/taie/util/collection/SparseBitSet.java | 3 +++ src/test/java/pascal/taie/util/collection/IBitSetTest.java | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/main/java/pascal/taie/util/collection/RegularBitSet.java b/src/main/java/pascal/taie/util/collection/RegularBitSet.java index 111dfcda8..ef12b31b3 100644 --- a/src/main/java/pascal/taie/util/collection/RegularBitSet.java +++ b/src/main/java/pascal/taie/util/collection/RegularBitSet.java @@ -312,6 +312,9 @@ public int previousClearBit(int fromIndex) { @Override public boolean intersects(IBitSet set) { + if (this.isEmpty() || set.isEmpty()) { + return false; + } if (this == set) { return true; } diff --git a/src/main/java/pascal/taie/util/collection/SparseBitSet.java b/src/main/java/pascal/taie/util/collection/SparseBitSet.java index b0599e164..b848b294e 100644 --- a/src/main/java/pascal/taie/util/collection/SparseBitSet.java +++ b/src/main/java/pascal/taie/util/collection/SparseBitSet.java @@ -482,6 +482,9 @@ public int previousClearBit(int fromIndex) { @Override public boolean intersects(IBitSet set) { + if (this.isEmpty() || set.isEmpty()) { + return false; + } if (this == set) { return true; } diff --git a/src/test/java/pascal/taie/util/collection/IBitSetTest.java b/src/test/java/pascal/taie/util/collection/IBitSetTest.java index 89692bee8..883848345 100644 --- a/src/test/java/pascal/taie/util/collection/IBitSetTest.java +++ b/src/test/java/pascal/taie/util/collection/IBitSetTest.java @@ -73,8 +73,10 @@ void testClear() { @Test void testIntersects() { IBitSet s1 = of(); + assertFalse(s1.intersects(s1)); IBitSet s2 = of(); assertFalse(s1.intersects(s2)); + assertFalse(s2.intersects(s1)); s2 = of(1, 233, 666); assertFalse(s1.intersects(s2)); assertFalse(s2.intersects(s1)); @@ -83,6 +85,7 @@ void testIntersects() { assertTrue(s2.intersects(s1)); s1.clear(666); assertFalse(s1.intersects(s2)); + assertFalse(s2.intersects(s1)); } @Test