diff --git a/release/c/wuffs-unsupported-snapshot.h b/release/c/wuffs-unsupported-snapshot.h index 5bce8864..1cba7041 100644 --- a/release/c/wuffs-unsupported-snapshot.h +++ b/release/c/wuffs-unsupported-snapshot.h @@ -2515,7 +2515,6 @@ extern "C" { // ---------------- Status Codes extern const char* wuffs_lzw__error__bad_code; -extern const char* wuffs_lzw__error__cyclical_prefix_chain; // ---------------- Public Consts @@ -9413,8 +9412,6 @@ exit: // ---------------- Status Codes Implementations const char* wuffs_lzw__error__bad_code = "?lzw: bad code"; -const char* wuffs_lzw__error__cyclical_prefix_chain = - "?lzw: cyclical prefix chain"; // ---------------- Private Consts @@ -9618,11 +9615,7 @@ wuffs_lzw__decoder__decode(wuffs_lzw__decoder* self, } while (v_c >= v_clear_code) { self->private_impl.f_stack[v_s] = self->private_impl.f_suffixes[v_c]; - if (v_s == 0) { - status = wuffs_lzw__error__cyclical_prefix_chain; - goto exit; - } - v_s -= 1; + v_s = ((v_s - 1) & 4095); v_c = ((uint32_t)(self->private_impl.f_prefixes[v_c])); } self->private_impl.f_stack[v_s] = ((uint8_t)(v_c)); diff --git a/std/lzw/decode_lzw.wuffs b/std/lzw/decode_lzw.wuffs index 043d8e3b..6edd5a63 100644 --- a/std/lzw/decode_lzw.wuffs +++ b/std/lzw/decode_lzw.wuffs @@ -13,7 +13,6 @@ // limitations under the License. pub status "?bad code" -pub status "?cyclical prefix chain" pub struct decoder?( literal_width base.u32[..8], @@ -99,10 +98,9 @@ pub func decoder.decode!??(dst base.io_writer, src base.io_reader) { post c < 256 via "a < b: a < c; c <= b"(c:clear_code), { this.stack[s] = this.suffixes[c] - if s == 0 { - return status "?cyclical prefix chain" - } - s -= 1 + // The bitwise-and with 4095 is algorithmically a no-op, but is + // necessary for the overflow checker. + s = (s ~mod- 1) & 4095 c = this.prefixes[c] as base.u32 } this.stack[s] = c as base.u8