wpkg test coverage results

Coverage test results of the Windows Packager by Made to Order Software Corporation.

LCOV - code coverage report
Current view: top level - zlib - inffast.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 128 144 88.9 %
Date: 2014-08-22 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* inffast.c -- fast decoding
       2             :  * Copyright (C) 1995-2008, 2010 Mark Adler
       3             :  * For conditions of distribution and use, see copyright notice in zlib.h
       4             :  */
       5             : 
       6             : #include "zutil.h"
       7             : #include "inftrees.h"
       8             : #include "inflate.h"
       9             : #include "inffast.h"
      10             : 
      11             : #ifndef ASMINF
      12             : 
      13             : /* Allow machine dependent optimization for post-increment or pre-increment.
      14             :    Based on testing to date,
      15             :    Pre-increment preferred for:
      16             :    - PowerPC G3 (Adler)
      17             :    - MIPS R5000 (Randers-Pehrson)
      18             :    Post-increment preferred for:
      19             :    - none
      20             :    No measurable difference:
      21             :    - Pentium III (Anderson)
      22             :    - M68060 (Nikl)
      23             :  */
      24             : #ifdef POSTINC
      25             : #  define OFF 0
      26             : #  define PUP(a) *(a)++
      27             : #else
      28             : #  define OFF 1
      29             : #  define PUP(a) *++(a)
      30             : #endif
      31             : 
      32             : /*
      33             :    Decode literal, length, and distance codes and write out the resulting
      34             :    literal and match bytes until either not enough input or output is
      35             :    available, an end-of-block is encountered, or a data error is encountered.
      36             :    When large enough input and output buffers are supplied to inflate(), for
      37             :    example, a 16K input buffer and a 64K output buffer, more than 95% of the
      38             :    inflate execution time is spent in this routine.
      39             : 
      40             :    Entry assumptions:
      41             : 
      42             :         state->mode == LEN
      43             :         strm->avail_in >= 6
      44             :         strm->avail_out >= 258
      45             :         start >= strm->avail_out
      46             :         state->bits < 8
      47             : 
      48             :    On return, state->mode is one of:
      49             : 
      50             :         LEN -- ran out of enough output space or enough available input
      51             :         TYPE -- reached end of block code, inflate() to interpret next block
      52             :         BAD -- error in block data
      53             : 
      54             :    Notes:
      55             : 
      56             :     - The maximum input bits used by a length/distance pair is 15 bits for the
      57             :       length code, 5 bits for the length extra, 15 bits for the distance code,
      58             :       and 13 bits for the distance extra.  This totals 48 bits, or six bytes.
      59             :       Therefore if strm->avail_in >= 6, then there is enough input to avoid
      60             :       checking for available input while decoding.
      61             : 
      62             :     - The maximum bytes that a single length/distance pair can output is 258
      63             :       bytes, which is the maximum length that can be coded.  inflate_fast()
      64             :       requires strm->avail_out >= 258 for each loop to avoid checking for
      65             :       output space.
      66             :  */
      67        8216 : void ZLIB_INTERNAL inflate_fast(strm, start)
      68             : z_streamp strm;
      69             : unsigned start;         /* inflate()'s starting value for strm->avail_out */
      70             : {
      71             :     struct inflate_state FAR *state;
      72             :     unsigned char FAR *in;      /* local strm->next_in */
      73             :     unsigned char FAR *last;    /* while in < last, enough input available */
      74             :     unsigned char FAR *out;     /* local strm->next_out */
      75             :     unsigned char FAR *beg;     /* inflate()'s initial strm->next_out */
      76             :     unsigned char FAR *end;     /* while out < end, enough space available */
      77             : #ifdef INFLATE_STRICT
      78             :     unsigned dmax;              /* maximum distance from zlib header */
      79             : #endif
      80             :     unsigned wsize;             /* window size or zero if not using window */
      81             :     unsigned whave;             /* valid bytes in the window */
      82             :     unsigned wnext;             /* window write index */
      83             :     unsigned char FAR *window;  /* allocated sliding window, if wsize != 0 */
      84             :     unsigned long hold;         /* local strm->hold */
      85             :     unsigned bits;              /* local strm->bits */
      86             :     code const FAR *lcode;      /* local strm->lencode */
      87             :     code const FAR *dcode;      /* local strm->distcode */
      88             :     unsigned lmask;             /* mask for first level of length codes */
      89             :     unsigned dmask;             /* mask for first level of distance codes */
      90             :     code here;                  /* retrieved table entry */
      91             :     unsigned op;                /* code bits, operation, extra bits, or */
      92             :                                 /*  window position, window bytes to copy */
      93             :     unsigned len;               /* match length, unused bytes */
      94             :     unsigned dist;              /* match distance */
      95             :     unsigned char FAR *from;    /* where to copy match from */
      96             : 
      97             :     /* copy state to local variables */
      98        8216 :     state = (struct inflate_state FAR *)strm->state;
      99        8216 :     in = strm->next_in - OFF;
     100        8216 :     last = in + (strm->avail_in - 5);
     101        8216 :     out = strm->next_out - OFF;
     102        8216 :     beg = out - (start - strm->avail_out);
     103        8216 :     end = out + (strm->avail_out - 257);
     104             : #ifdef INFLATE_STRICT
     105             :     dmax = state->dmax;
     106             : #endif
     107        8216 :     wsize = state->wsize;
     108        8216 :     whave = state->whave;
     109        8216 :     wnext = state->wnext;
     110        8216 :     window = state->window;
     111        8216 :     hold = state->hold;
     112        8216 :     bits = state->bits;
     113        8216 :     lcode = state->lencode;
     114        8216 :     dcode = state->distcode;
     115        8216 :     lmask = (1U << state->lenbits) - 1;
     116        8216 :     dmask = (1U << state->distbits) - 1;
     117             : 
     118             :     /* decode literals and length/distances until end-of-block or not enough
     119             :        input data or output space */
     120             :     do {
     121   105644790 :         if (bits < 15) {
     122    52709692 :             hold += (unsigned long)(PUP(in)) << bits;
     123    52709692 :             bits += 8;
     124    52709692 :             hold += (unsigned long)(PUP(in)) << bits;
     125    52709692 :             bits += 8;
     126             :         }
     127   105644790 :         here = lcode[hold & lmask];
     128             :       dolen:
     129   105758093 :         op = (unsigned)(here.bits);
     130   105758093 :         hold >>= op;
     131   105758093 :         bits -= op;
     132   105758093 :         op = (unsigned)(here.op);
     133   105758093 :         if (op == 0) {                          /* literal */
     134             :             Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ?
     135             :                     "inflate:         literal '%c'\n" :
     136             :                     "inflate:         literal 0x%02x\n", here.val));
     137   105352598 :             PUP(out) = (unsigned char)(here.val);
     138             :         }
     139      405495 :         else if (op & 16) {                     /* length base */
     140      287035 :             len = (unsigned)(here.val);
     141      287035 :             op &= 15;                           /* number of extra bits */
     142      287035 :             if (op) {
     143       91129 :                 if (bits < op) {
     144        4212 :                     hold += (unsigned long)(PUP(in)) << bits;
     145        4212 :                     bits += 8;
     146             :                 }
     147       91129 :                 len += (unsigned)hold & ((1U << op) - 1);
     148       91129 :                 hold >>= op;
     149       91129 :                 bits -= op;
     150             :             }
     151             :             Tracevv((stderr, "inflate:         length %u\n", len));
     152      287035 :             if (bits < 15) {
     153      158986 :                 hold += (unsigned long)(PUP(in)) << bits;
     154      158986 :                 bits += 8;
     155      158986 :                 hold += (unsigned long)(PUP(in)) << bits;
     156      158986 :                 bits += 8;
     157             :             }
     158      287035 :             here = dcode[hold & dmask];
     159             :           dodist:
     160      291222 :             op = (unsigned)(here.bits);
     161      291222 :             hold >>= op;
     162      291222 :             bits -= op;
     163      291222 :             op = (unsigned)(here.op);
     164      291222 :             if (op & 16) {                      /* distance base */
     165      287035 :                 dist = (unsigned)(here.val);
     166      287035 :                 op &= 15;                       /* number of extra bits */
     167      287035 :                 if (bits < op) {
     168        1616 :                     hold += (unsigned long)(PUP(in)) << bits;
     169        1616 :                     bits += 8;
     170        1616 :                     if (bits < op) {
     171           0 :                         hold += (unsigned long)(PUP(in)) << bits;
     172           0 :                         bits += 8;
     173             :                     }
     174             :                 }
     175      287035 :                 dist += (unsigned)hold & ((1U << op) - 1);
     176             : #ifdef INFLATE_STRICT
     177             :                 if (dist > dmax) {
     178             :                     strm->msg = (char *)"invalid distance too far back";
     179             :                     state->mode = BAD;
     180             :                     break;
     181             :                 }
     182             : #endif
     183      287035 :                 hold >>= op;
     184      287035 :                 bits -= op;
     185             :                 Tracevv((stderr, "inflate:         distance %u\n", dist));
     186      287035 :                 op = (unsigned)(out - beg);     /* max distance in output */
     187      287035 :                 if (dist > op) {                /* see if copy from window */
     188        4805 :                     op = dist - op;             /* distance back in window */
     189        4805 :                     if (op > whave) {
     190           0 :                         if (state->sane) {
     191           0 :                             strm->msg =
     192             :                                 (char *)"invalid distance too far back";
     193           0 :                             state->mode = BAD;
     194           0 :                             break;
     195             :                         }
     196             : #ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR
     197             :                         if (len <= op - whave) {
     198             :                             do {
     199             :                                 PUP(out) = 0;
     200             :                             } while (--len);
     201             :                             continue;
     202             :                         }
     203             :                         len -= op - whave;
     204             :                         do {
     205             :                             PUP(out) = 0;
     206             :                         } while (--op > whave);
     207             :                         if (op == 0) {
     208             :                             from = out - dist;
     209             :                             do {
     210             :                                 PUP(out) = PUP(from);
     211             :                             } while (--len);
     212             :                             continue;
     213             :                         }
     214             : #endif
     215             :                     }
     216        4805 :                     from = window - OFF;
     217        4805 :                     if (wnext == 0) {           /* very common case */
     218        4337 :                         from += wsize - op;
     219        4337 :                         if (op < len) {         /* some from window */
     220          48 :                             len -= op;
     221             :                             do {
     222        3925 :                                 PUP(out) = PUP(from);
     223        3925 :                             } while (--op);
     224        4337 :                             from = out - dist;  /* rest from output */
     225             :                         }
     226             :                     }
     227         468 :                     else if (wnext < op) {      /* wrap around window */
     228         302 :                         from += wsize + wnext - op;
     229         302 :                         op -= wnext;
     230         302 :                         if (op < len) {         /* some from end of window */
     231           1 :                             len -= op;
     232             :                             do {
     233           2 :                                 PUP(out) = PUP(from);
     234           2 :                             } while (--op);
     235           1 :                             from = window - OFF;
     236           1 :                             if (wnext < len) {  /* some from start of window */
     237           0 :                                 op = wnext;
     238           0 :                                 len -= op;
     239             :                                 do {
     240           0 :                                     PUP(out) = PUP(from);
     241           0 :                                 } while (--op);
     242         302 :                                 from = out - dist;      /* rest from output */
     243             :                             }
     244             :                         }
     245             :                     }
     246             :                     else {                      /* contiguous in window */
     247         166 :                         from += wnext - op;
     248         166 :                         if (op < len) {         /* some from window */
     249           1 :                             len -= op;
     250             :                             do {
     251         204 :                                 PUP(out) = PUP(from);
     252         204 :                             } while (--op);
     253           1 :                             from = out - dist;  /* rest from output */
     254             :                         }
     255             :                     }
     256       64855 :                     while (len > 2) {
     257       60050 :                         PUP(out) = PUP(from);
     258       60050 :                         PUP(out) = PUP(from);
     259       60050 :                         PUP(out) = PUP(from);
     260       60050 :                         len -= 3;
     261             :                     }
     262        4805 :                     if (len) {
     263        2465 :                         PUP(out) = PUP(from);
     264        2465 :                         if (len > 1)
     265        4805 :                             PUP(out) = PUP(from);
     266             :                     }
     267             :                 }
     268             :                 else {
     269      282230 :                     from = out - dist;          /* copy direct from output */
     270             :                     do {                        /* minimum length is three */
     271     9178572 :                         PUP(out) = PUP(from);
     272     9178572 :                         PUP(out) = PUP(from);
     273     9178572 :                         PUP(out) = PUP(from);
     274     9178572 :                         len -= 3;
     275     9178572 :                     } while (len > 2);
     276      282230 :                     if (len) {
     277       92635 :                         PUP(out) = PUP(from);
     278       92635 :                         if (len > 1)
     279      287035 :                             PUP(out) = PUP(from);
     280             :                     }
     281             :                 }
     282             :             }
     283        4187 :             else if ((op & 64) == 0) {          /* 2nd level distance code */
     284        4187 :                 here = dcode[here.val + (hold & ((1U << op) - 1))];
     285        4187 :                 goto dodist;
     286             :             }
     287             :             else {
     288           0 :                 strm->msg = (char *)"invalid distance code";
     289           0 :                 state->mode = BAD;
     290           0 :                 break;
     291             :             }
     292             :         }
     293      118460 :         else if ((op & 64) == 0) {              /* 2nd level length code */
     294      113303 :             here = lcode[here.val + (hold & ((1U << op) - 1))];
     295      113303 :             goto dolen;
     296             :         }
     297        5157 :         else if (op & 32) {                     /* end-of-block */
     298             :             Tracevv((stderr, "inflate:         end of block\n"));
     299        5157 :             state->mode = TYPE;
     300        5157 :             break;
     301             :         }
     302             :         else {
     303           0 :             strm->msg = (char *)"invalid literal/length code";
     304           0 :             state->mode = BAD;
     305           0 :             break;
     306             :         }
     307   105639633 :     } while (in < last && out < end);
     308             : 
     309             :     /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
     310        8216 :     len = bits >> 3;
     311        8216 :     in -= len;
     312        8216 :     bits -= len << 3;
     313        8216 :     hold &= (1U << bits) - 1;
     314             : 
     315             :     /* update state and return */
     316        8216 :     strm->next_in = in + OFF;
     317        8216 :     strm->next_out = out + OFF;
     318        8216 :     strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
     319        8216 :     strm->avail_out = (unsigned)(out < end ?
     320        8216 :                                  257 + (end - out) : 257 - (out - end));
     321        8216 :     state->hold = hold;
     322        8216 :     state->bits = bits;
     323        8216 :     return;
     324             : }
     325             : 
     326             : /*
     327             :    inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
     328             :    - Using bit fields for code structure
     329             :    - Different op definition to avoid & for extra bits (do & for table bits)
     330             :    - Three separate decoding do-loops for direct, window, and wnext == 0
     331             :    - Special case for distance > 1 copies to do overlapped load and store copy
     332             :    - Explicit branch predictions (based on measured branch probabilities)
     333             :    - Deferring match copy and interspersed it with decoding subsequent codes
     334             :    - Swapping literal/length else
     335             :    - Swapping window/direct else
     336             :    - Larger unrolled copy loops (three is about right)
     337             :    - Moving len -= 3 statement into middle of loop
     338             :  */
     339             : 
     340             : #endif /* !ASMINF */

Generated by: LCOV version 1.9

The wpkg tool is an open source tool created by Made to Order Software Corporation.