From: Nathan Moinvaziri Date: Wed, 25 Mar 2026 00:34:05 +0000 (-0700) Subject: Simplify safe-mode copy path selection in inflate_fast X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=554dde03042cfadc7502aa0f8a11fbd9a4756702;p=thirdparty%2Fzlib-ng.git Simplify safe-mode copy path selection in inflate_fast The branch structure now tests safe_mode directly, which is clearer and produces the same code on all platforms. No functional change to the copy operations used. --- diff --git a/inffast_tpl.h b/inffast_tpl.h index 0557231c0..ed253de95 100644 --- a/inffast_tpl.h +++ b/inffast_tpl.h @@ -246,23 +246,25 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start, int safe_mod out = CHUNKUNROLL(out, &dist, &len); out = CHUNKCOPY_SAFE(out, out - dist, len, safe); } else { +#ifdef HAVE_MASKED_READWRITE + out = CHUNKCOPY_SAFE(out, from, op, safe); + out = CHUNKCOPY_SAFE(out, out - dist, len, safe); +#else out = chunkcopy_safe(out, from, op, safe); out = chunkcopy_safe(out, out - dist, len, safe); +#endif } } else { -#ifndef HAVE_MASKED_READWRITE - if (UNLIKELY(safe_mode)) - out = chunkcopy_safe(out, from, len, safe); +#ifdef HAVE_MASKED_READWRITE + out = CHUNKCOPY_SAFE(out, from, len, safe); +#else + if (LIKELY(!safe_mode)) + out = CHUNKCOPY_SAFE(out, from, len, safe); else + out = chunkcopy_safe(out, from, len, safe); #endif - out = CHUNKCOPY_SAFE(out, from, len, safe); } -#ifndef HAVE_MASKED_READWRITE - } else if (UNLIKELY(safe_mode)) { - /* Whole reference is in range of current output. */ - out = chunkcopy_safe(out, out - dist, len, safe); -#endif - } else { + } else if (LIKELY(!safe_mode)) { /* Whole reference is in range of current output. No range checks are necessary because we start with room for at least 258 bytes of output, so unroll and roundoff operations can write beyond `out+len` so long @@ -272,6 +274,12 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start, int safe_mod out = CHUNKCOPY(out, out - dist, len); else out = CHUNKMEMSET(out, out - dist, len); + } else { +#ifdef HAVE_MASKED_READWRITE + out = CHUNKCOPY_SAFE(out, out - dist, len, safe); +#else + out = chunkcopy_safe(out, out - dist, len, safe); +#endif } } else if (UNLIKELY((op & 64) == 0)) { /* 2nd level distance code */ here = dcode[here.val + BITS(op)];