From: Paul Eggert Date: Sun, 4 May 2003 06:29:51 +0000 (+0000) Subject: (BITSET_FOR_EACH, BITSET_FOR_EACH_REVERSE): X-Git-Tag: BISON-2_0~315 X-Git-Url: https://git.saurik.com/bison.git/commitdiff_plain/2175bfbd0996b5570f50df01577166ca8ffe9dea?ds=inline (BITSET_FOR_EACH, BITSET_FOR_EACH_REVERSE): Do not overrun array bounds. This should fix a bug reported today by Olatunji Oluwabukunmi in . --- diff --git a/lib/bitset.h b/lib/bitset.h index c659a2ce..0dc1cdff 100644 --- a/lib/bitset.h +++ b/lib/bitset.h @@ -1,5 +1,5 @@ /* Generic bitsets. - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz). This program is free software; you can redistribute it and/or modify @@ -292,7 +292,6 @@ extern void bitset_dump PARAMS ((FILE *, bitset)); bitset_bindex i; bitset_iterator iter; - bitset_zero (dst); BITSET_FOR_EACH (iter, src, i, 0) { printf ("%ld ", i); @@ -303,7 +302,9 @@ extern void bitset_dump PARAMS ((FILE *, bitset)); (ITER.num == BITSET_LIST_SIZE) \ && (ITER.num = bitset_list (BSET, ITER.list, \ BITSET_LIST_SIZE, &ITER.next));) \ - for (ITER.i = 0; (BIT) = ITER.list[ITER.i], ITER.i < ITER.num; ITER.i++) + for (ITER.i = 0; \ + ITER.i < ITER.num && ((BIT) = ITER.list[ITER.i], 1); \ + ITER.i++) /* Loop over all elements of BSET, in reverse order starting with @@ -313,7 +314,6 @@ extern void bitset_dump PARAMS ((FILE *, bitset)); bitset_bindex i; bitset_iterator iter; - bitset_zero (dst); BITSET_FOR_EACH_REVERSE (iter, src, i, 0) { printf ("%ld ", i); @@ -324,7 +324,9 @@ extern void bitset_dump PARAMS ((FILE *, bitset)); (ITER.num == BITSET_LIST_SIZE) \ && (ITER.num = bitset_list_reverse (BSET, ITER.list, \ BITSET_LIST_SIZE, &ITER.next));) \ - for (ITER.i = 0; (BIT) = ITER.list[ITER.i], ITER.i < ITER.num; ITER.i++) + for (ITER.i = 0; \ + ITER.i < ITER.num && ((BIT) = ITER.list[ITER.i], 1); \ + ITER.i++) /* Define set operations in terms of logical operations. */