This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Re: bitset bug in libstdc++-2.90.7
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: Re: bitset bug in libstdc++-2.90.7
- From: Anders Widell <d95-awi at nada dot kth dot se>
- Date: Sun, 30 Jan 2000 22:42:07 +0100 (MET)
Hi again!
Didn't anyone care to apply my patch?
On Sat, 15 Jan 2000, Anders Widell wrote:
> 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
>