Skip to content

Commit f57b2e9

Browse files
authored
Merge pull request #12 from haskell/fix-issue-11
Change the window bits range from 8..15 to 9..15
2 parents adc6a06 + 26d9115 commit f57b2e9

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

Codec/Compression/Zlib/Stream.hsc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,8 @@ fromCompressionLevel (CompressionLevel n)
709709
-- usage.
710710
--
711711
-- The compression window size is the value of the the window bits raised to
712-
-- the power 2. The window bits must be in the range @8..15@ which corresponds
713-
-- to compression window sizes of 256b to 32Kb. The default is 15 which is also
712+
-- the power 2. The window bits must be in the range @9..15@ which corresponds
713+
-- to compression window sizes of 512b to 32Kb. The default is 15 which is also
714714
-- the maximum size.
715715
--
716716
-- The total amount of memory used depends on the window bits and the
@@ -737,19 +737,19 @@ data WindowBits = WindowBits Int
737737
defaultWindowBits :: WindowBits
738738
defaultWindowBits = WindowBits 15
739739

740-
-- | A specific compression window size, specified in bits in the range @8..15@
740+
-- | A specific compression window size, specified in bits in the range @9..15@
741741
--
742742
windowBits :: Int -> WindowBits
743743
windowBits n
744-
| n >= 8 && n <= 15 = WindowBits n
745-
| otherwise = error "WindowBits must be in the range 8..15"
744+
| n >= 9 && n <= 15 = WindowBits n
745+
| otherwise = error "WindowBits must be in the range 9..15"
746746

747747
fromWindowBits :: Format -> WindowBits-> CInt
748748
fromWindowBits format bits = (formatModifier format) (checkWindowBits bits)
749749
where checkWindowBits DefaultWindowBits = 15
750750
checkWindowBits (WindowBits n)
751-
| n >= 8 && n <= 15 = fromIntegral n
752-
| otherwise = error "WindowBits must be in the range 8..15"
751+
| n >= 9 && n <= 15 = fromIntegral n
752+
| otherwise = error "WindowBits must be in the range 9..15"
753753
formatModifier Zlib = id
754754
formatModifier GZip = (+16)
755755
formatModifier GZipOrZlib = (+32)

test/Test.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ prop_decompress_after_compress :: Format
6161
-> Property
6262
prop_decompress_after_compress w cp dp =
6363
(w /= zlibFormat || decompressWindowBits dp >= compressWindowBits cp) &&
64-
-- Zlib decompression has been observed to fail with both compress and decompress
65-
-- window bits = 8. This seems to be contrary to the docs and to a quick reading
66-
-- of the zlib source code.
67-
(decompressWindowBits dp > compressWindowBits cp || decompressWindowBits dp > WindowBits 8) &&
64+
(decompressWindowBits dp > compressWindowBits cp) &&
6865
decompressBufferSize dp > 0 && compressBufferSize cp > 0 ==>
6966
liftM2 (==) (decompress w dp . compress w cp) id
7067

test/Test/Codec/Compression/Zlib/Stream.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ instance Arbitrary CompressionLevel where
2424

2525

2626
instance Arbitrary WindowBits where
27-
arbitrary = elements $ defaultWindowBits:map windowBits [8..15]
27+
arbitrary = elements $ defaultWindowBits:map windowBits [9..15]
2828

2929

3030
instance Arbitrary MemoryLevel where

0 commit comments

Comments
 (0)