From: Janne Hellsten <janne@hy...>  20041218 18:46:15

I was writing a test for Extlib's BitSet and encountered a weird case. The following does not seem to work as it is supposed to work (intersection of a set with the empty set produces a nonempty set). Run function test_rnd_creation for the buggy behaviour. For some reason test_intersect does not exhibit the same behaviour. A quick glance at the BitSet.intersect would suggest that it is reading past the second argument bit array (bget uses string_unsafe_get). I incorporated this into my tester, but didn't enable it yet. Apologies if this has already been fixed in CVS. I'm using the released 1.3 version. Here is the source for the test case: <snip> module B = BitSet let bitset_of_int n = assert (n <= (1 lsl 29)); let s = B.create 30 in for i = 0 to 29 do if (n land (1 lsl i)) <> 0 then B.set s i done; s let int_of_bitset s = let n = ref 0 in for i = 0 to 29 do if B.is_set s i then n := !n lor (1 lsl i) done; !n let test_rnd_creation () = for i = 0 to 255 do let r1 = Random.int (1 lsl 28) in let s = bitset_of_int r1 in let c = B.copy s in assert (int_of_bitset s = r1); assert (c = s); assert (B.compare c s = 0); B.unite c s; assert (c = s); B.intersect c (B.empty ()); assert (B.count c = 0); done let test_intersect () = for i = 0 to 2550 do let s = bitset_of_int (Random.int 1 lsl 28) in B.intersect s (B.empty ()); assert (B.count s = 0) done </snip> ciao, janne 