diff --git a/gen/c/std/lzw.c b/gen/c/std/lzw.c index 9d735986..7dd27b43 100644 --- a/gen/c/std/lzw.c +++ b/gen/c/std/lzw.c @@ -2170,7 +2170,6 @@ wuffs_base__status wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self, v_width = (v_literal_width + 1); v_bits = 0; v_n_bits = 0; - label_0_continue:; while (true) { while (v_n_bits < v_width) { { @@ -2197,12 +2196,16 @@ wuffs_base__status wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self, self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_code)); self->private_impl.f_prefixes[v_save_code] = ((uint16_t)(v_prev_code)); + v_save_code += 1; + if ((v_save_code == (((uint32_t)(1)) << v_width)) && (v_width < 12)) { + v_width += 1; + } } + v_prev_code = v_code; } else if (v_code == v_clear_code) { v_save_code = v_end_code; v_prev_code = 0; v_width = (v_literal_width + 1); - goto label_0_continue; } else if (v_code == v_end_code) { status = WUFFS_BASE__STATUS_OK; goto ok; @@ -2234,29 +2237,27 @@ wuffs_base__status wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self, v_n_copied = wuffs_base__io_writer__copy_from_slice( &ioptr_dst, iobounds1_dst, v_expansion); if (v_n_copied == ((uint64_t)(v_expansion.len))) { - goto label_1_break; + goto label_0_break; } v_s = ((v_s + ((uint32_t)((v_n_copied & 4095)))) & 4095); status = WUFFS_BASE__SUSPENSION_SHORT_WRITE; WUFFS_BASE__COROUTINE_SUSPENSION_POINT_MAYBE_SUSPEND(3); } - label_1_break:; + label_0_break:; if (v_save_code <= 4095) { self->private_impl.f_suffixes[v_save_code] = ((uint8_t)(v_c)); self->private_impl.f_prefixes[v_save_code] = ((uint16_t)(v_prev_code)); + v_save_code += 1; + if ((v_save_code == (((uint32_t)(1)) << v_width)) && (v_width < 12)) { + v_width += 1; + } } + v_prev_code = v_code; } else { status = WUFFS_LZW__ERROR_BAD_CODE; goto exit; } - if (v_save_code <= 4095) { - v_save_code += 1; - if ((v_save_code == (((uint32_t)(1)) << v_width)) && (v_width < 12)) { - v_width += 1; - } - } - v_prev_code = v_code; } goto ok; diff --git a/std/lzw/decode_lzw.wuffs b/std/lzw/decode_lzw.wuffs index 15136229..e87c54d3 100644 --- a/std/lzw/decode_lzw.wuffs +++ b/std/lzw/decode_lzw.wuffs @@ -72,13 +72,17 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader)() { if save_code <= 4095 { this.suffixes[save_code] = code as base.u8 this.prefixes[save_code] = prev_code as base.u16 + save_code += 1 + if (save_code == ((1 as base.u32) << width)) and (width < 12) { + width += 1 + } } + prev_code = code } else if code == clear_code { save_code = end_code prev_code = 0 width = literal_width + 1 - continue } else if code == end_code { return @@ -126,18 +130,15 @@ pub func decoder.decode?(dst base.io_writer, src base.io_reader)() { if save_code <= 4095 { this.suffixes[save_code] = c as base.u8 this.prefixes[save_code] = prev_code as base.u16 + save_code += 1 + if (save_code == ((1 as base.u32) << width)) and (width < 12) { + width += 1 + } } + prev_code = code } else { return error "bad code" } - - if save_code <= 4095 { - save_code += 1 - if (save_code == ((1 as base.u32) << width)) and (width < 12) { - width += 1 - } - } - prev_code = code } }