]> Savannah Git Hosting - gnulib.git/commitdiff
bitset: fix overflows
authorAkim Demaille <akim.demaille@gmail.com>
Sat, 16 Mar 2019 16:16:48 +0000 (17:16 +0100)
committerAkim Demaille <akim.demaille@gmail.com>
Sun, 17 Mar 2019 07:35:55 +0000 (08:35 +0100)
Reported by Bruno Haible.
https://lists.gnu.org/archive/html/bug-gnulib/2019-03/msg00017.html

* lib/bitset/table.c (tbitset_test): last_bit is the position of
the bit in the array of bitset_word, so be sure to take its modulo
number-of-bits-in-bitset-word (i.e., EBITSET_ELT_WORDS).
* lib/bitset/list.c (lbitset_unused_clear): Likewise.

ChangeLog
lib/bitset/list.c
lib/bitset/table.c

index a3fbce6e74de546c4a90f992ba214951648f088b..ff1e5f4dd44959ec00f5536d917356f335ee053e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2019-03-16  Akim Demaille  <akim@lrde.epita.fr>
+
+       bitset: fix overflows.
+       Reported by Bruno Haible.
+       https://lists.gnu.org/archive/html/bug-gnulib/2019-03/msg00017.html
+       * lib/bitset/table.c (tbitset_test): last_bit is the position of
+       the bit in the array of bitset_word, so be sure to take its modulo
+       number-of-bits-in-bitset-word (i.e., EBITSET_ELT_WORDS).
+       * lib/bitset/list.c (lbitset_unused_clear): Likewise.
+
 2019-03-14  Akim Demaille  <akim@lrde.epita.fr>
 
        bitset: style changes.
index f42edb8ea3ec452cb73e89ece851dcf808fa7c10..fe1b52869b8afbb7ae4681474f55ca73ce7942e1 100644 (file)
@@ -859,7 +859,8 @@ lbitset_unused_clear (bitset dst)
       bitset_word *srcp = elt->words;
       bitset_windex windex = n_bits / BITSET_WORD_BITS;
 
-      srcp[windex - elt->index] &= ((bitset_word) 1 << last_bit) - 1;
+      srcp[windex - elt->index]
+        &= ((bitset_word) 1 << (last_bit % BITSET_WORD_BITS)) - 1;
       windex++;
 
       for (; (windex - elt->index) < LBITSET_ELT_WORDS; windex++)
index a129c8712a3768c0011fe51aed3337297c15cde7..9cac964694a72db15bd6d5bb892e17f8bcf87736 100644 (file)
@@ -778,7 +778,8 @@ tbitset_unused_clear (bitset dst)
           bitset_windex windex = n_bits / BITSET_WORD_BITS;
           bitset_windex woffset = eindex * EBITSET_ELT_WORDS;
 
-          srcp[windex - woffset] &= ((bitset_word) 1 << last_bit) - 1;
+          srcp[windex - woffset]
+            &= ((bitset_word) 1 << (last_bit % BITSET_WORD_BITS)) - 1;
           windex++;
           for (; (windex - woffset) < EBITSET_ELT_WORDS; windex++)
             srcp[windex - woffset] = 0;