Expose long hidden bug.
Bug discovered by Alexander Polakov.
We change how putBool works to expose it, making it easier to fix,
lots of tests in the test suite breaks by this change,
but they shouldn't.
putWord8 is broken, as it may let bits we want to be unused leak into
the output. If some high bits are set in a Word8, but we don't want to
output them, they will anyway leak and corrupt previously written bits.
The following program is now broken with this commit;
broken = do
putBool False
putBool True
It'll output a byte: 11000000
instead of the expected: 01000000
commit4dbf32a91c053ecf52e9c9f950ff5adf28357ed8
authorLennart Kolmodin <kolmodin@gmail.com>
dateSat 6 Apr 2013, 14:11 (14 years ago)
parentac8e0ca
Data/Binary/Bits/Put.hs+1−1
@@ -50,7 +50,7 @@ data S = S !Builder !Word8 !Int
5050
5151-- | Put a 1 bit 'Bool'.
5252putBool :: Bool -> BitPut ()
53−putBool b = putWord8 1 (if b then 1 else 0)
53+putBool b = putWord8 1 (if b then 0xff else 0x00)
5454
5555-- | Put the @n@ lower bits of a 'Word8'.
5656putWord8 :: Int -> Word8 -> BitPut ()