]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Reorder variables in inflate functions to reduce padding holes
authorHans Kristian Rosbach <hk-git@circlestorm.org>
Wed, 9 Oct 2024 14:27:43 +0000 (16:27 +0200)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Thu, 10 Oct 2024 11:22:50 +0000 (13:22 +0200)
due to variable alignment requirements.

inffast_tpl.h
inflate.c

index 1b36acaa35340a53117b918819344ab176dbeb32..23a6abd84b227e319b0eaef4236588d17c2bfaa7 100644 (file)
@@ -59,10 +59,10 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) {
     unsigned char *beg;         /* inflate()'s initial strm->next_out */
     unsigned char *end;         /* while out < end, enough space available */
     unsigned char *safe;        /* can use chunkcopy provided out < safe */
+    unsigned char *window;      /* allocated sliding window, if wsize != 0 */
     unsigned wsize;             /* window size or zero if not using window */
     unsigned whave;             /* valid bytes in the window */
     unsigned wnext;             /* window write index */
-    unsigned char *window;      /* allocated sliding window, if wsize != 0 */
 
     /* hold is a local copy of strm->hold. By default, hold satisfies the same
        invariants that strm->hold does, namely that (hold >> bits) == 0. This
@@ -101,18 +101,18 @@ void Z_INTERNAL INFLATE_FAST(PREFIX3(stream) *strm, uint32_t start) {
        with (1<<bits)-1 to drop those excess bits so that, on function exit, we
        keep the invariant that (state->hold >> state->bits) == 0.
     */
-    uint64_t hold;              /* local strm->hold */
     unsigned bits;              /* local strm->bits */
-    code const *lcode;          /* local strm->lencode */
-    code const *dcode;          /* local strm->distcode */
+    uint64_t hold;              /* local strm->hold */
     unsigned lmask;             /* mask for first level of length codes */
     unsigned dmask;             /* mask for first level of distance codes */
+    code const *lcode;          /* local strm->lencode */
+    code const *dcode;          /* local strm->distcode */
     const code *here;           /* retrieved table entry */
     unsigned op;                /* code bits, operation, extra bits, or */
                                 /*  window position, window bytes to copy */
     unsigned len;               /* match length, unused bytes */
-    unsigned dist;              /* match distance */
     unsigned char *from;        /* where to copy match from */
+    unsigned dist;              /* match distance */
     unsigned extra_safe;        /* copy chunks safely in all cases */
 
     /* copy state to local variables */
index 2ce508f8d03b728da0d6f816e6786686f15e59b2..5a89a4bb30c8fa38dea4db1f6af59dfb6dd90669 100644 (file)
--- a/inflate.c
+++ b/inflate.c
@@ -217,8 +217,8 @@ Z_INTERNAL void free_inflate(PREFIX3(stream) *strm) {
  * This function is hidden in ZLIB_COMPAT builds.
  */
 int32_t ZNG_CONDEXPORT PREFIX(inflateInit2)(PREFIX3(stream) *strm, int32_t windowBits) {
-    int32_t ret;
     struct inflate_state *state;
+    int32_t ret;
 
     /* Initialize functable */
     FUNCTABLE_INIT;
@@ -477,12 +477,12 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
     struct inflate_state *state;
     const unsigned char *next;  /* next input */
     unsigned char *put;         /* next output */
+    unsigned char *from;        /* where to copy match bytes from */
     unsigned have, left;        /* available input and output */
     uint32_t hold;              /* bit buffer */
     unsigned bits;              /* bits in bit buffer */
     uint32_t in, out;           /* save starting available input and output */
     unsigned copy;              /* number of stored or match bytes to copy */
-    unsigned char *from;        /* where to copy match bytes from */
     code here;                  /* current decoding table entry */
     code last;                  /* parent table entry */
     unsigned len;               /* length to copy for repeats, bits to drop */
@@ -1306,11 +1306,11 @@ static uint32_t syncsearch(uint32_t *have, const uint8_t *buf, uint32_t len) {
 }
 
 int32_t Z_EXPORT PREFIX(inflateSync)(PREFIX3(stream) *strm) {
+    struct inflate_state *state;
+    size_t in, out;             /* temporary to save total_in and total_out */
     unsigned len;               /* number of bytes to look at or looked at */
     int flags;                  /* temporary to save header status */
-    size_t in, out;             /* temporary to save total_in and total_out */
     unsigned char buf[4];       /* to restore bit buffer to byte string */
-    struct inflate_state *state;
 
     /* check parameters */
     if (inflateStateCheck(strm))