This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
bitset bug in libstdc++-2.90.7
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: bitset bug in libstdc++-2.90.7
- From: Anders Widell <d95-awi at nada dot kth dot se>
- Date: Sat, 15 Jan 2000 22:19:56 +0100 (MET)
I've found and fixed a bug in libstdc++-2.90.7. Here is a small
program that triggers the bug (but only on 32-bit machines):
#include <iostream>
#include <bitset>
int main() {
bitset<70> s = 15;
cout << "Before shift:" << endl << s << endl;
s <<= 32;
cout << "After shift:" << endl << s << endl;
}
The program gives the following output:
Before shift:
0000000000000000000000000000000000000000000000000000000000000000001111
After shift:
0011110000000000000000000000000000111100000000000000000000000000000000
The problem occurs when a bitset occupies more than two machine words
and is shifted by a multiple of the word size. Then the code shifts a
word by the word size. It would have been correct if such a shift had
cleared the word, but in fact it does nothing. This is because the
cpu only uses the least significant bits of the shift value, so
shifting by the word size is equal to shifting no steps at all.
I've created a patch that fixes this bug by adding an AND operation
after the shift in such a way that the word is cleard when it is
shifted by the word size.
/ Anders Widell
bitset-patch.tgz