Allow an LZW literal width of 0

This commit is contained in:
Nigel Tao committed 2019-05-26 15:52:07 +10:00
1 parent af4e327a8f
commit d41430c4f5
3 files changed
+16 -16

No files matched your search

+8 -8
View File
@@ -27,11 +27,11 @@ pri status "#internal error: inconsistent I/O"
pub const decoder_workbuf_len_max_incl_worst_case base.u64 = 0
pub struct decoder?(
// set_literal_width_arg is the saved argument passed to set_literal_width.
// This field is copied to the literal_width field at the start of
// decode_io_writer. During that method, calling set_literal_width will
// change set_literal_width_arg but not literal_width.
set_literal_width_arg base.u32[..8],
// set_literal_width_arg is 1 plus the saved argument passed to
// set_literal_width. This is assigned to the literal_width field at the
// start of decode_io_writer. During that method, calling set_literal_width
// will change set_literal_width_arg but not literal_width.
set_literal_width_arg base.u32[..9],
// read_from state that does not change during a decode call.
literal_width base.u32[..8],
@@ -69,8 +69,8 @@ pub struct decoder?(
output array[8192 + 7] base.u8,
)
pub func decoder.set_literal_width!(lw base.u32[1..8]) {
this.set_literal_width_arg = args.lw
pub func decoder.set_literal_width!(lw base.u32[..8]) {
this.set_literal_width_arg = args.lw + 1
}
pub func decoder.workbuf_len() base.range_ii_u64 {
@@ -83,7 +83,7 @@ pub func decoder.decode_io_writer?(dst base.io_writer, src base.io_reader, workb
// Initialize read_from state.
this.literal_width = 8
if this.set_literal_width_arg > 0 {
this.literal_width = this.set_literal_width_arg
this.literal_width = this.set_literal_width_arg - 1
}
this.clear_code = (1 as base.u32) << this.literal_width
this.end_code = this.clear_code + 1