Diff for /embedaddon/rsync/zlib/inftrees.c between versions 1.1.1.1 and 1.1.1.2

version 1.1.1.1, 2012/02/17 15:09:30 version 1.1.1.2, 2013/10/14 07:51:14
Line 1 Line 1
 /* inftrees.c -- generate Huffman trees for efficient decoding  /* inftrees.c -- generate Huffman trees for efficient decoding
 * Copyright (C) 1995-2005 Mark Adler * Copyright (C) 1995-2013 Mark Adler
  * For conditions of distribution and use, see copyright notice in zlib.h   * For conditions of distribution and use, see copyright notice in zlib.h
  */   */
   
Line 9 Line 9
 #define MAXBITS 15  #define MAXBITS 15
   
 const char inflate_copyright[] =  const char inflate_copyright[] =
   " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";   " inflate 1.2.8 Copyright 1995-2013 Mark Adler ";
 /*  /*
   If you use the zlib library in a product, an acknowledgment is welcome    If you use the zlib library in a product, an acknowledgment is welcome
   in the documentation of your product. If for some reason you cannot    in the documentation of your product. If for some reason you cannot
Line 29  const char inflate_copyright[] = Line 29  const char inflate_copyright[] =
    table index bits.  It will differ if the request is greater than the     table index bits.  It will differ if the request is greater than the
    longest code or if it is less than the shortest code.     longest code or if it is less than the shortest code.
  */   */
int inflate_table(type, lens, codes, table, bits, work)int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work)
 codetype type;  codetype type;
 unsigned short FAR *lens;  unsigned short FAR *lens;
 unsigned codes;  unsigned codes;
Line 50  unsigned short FAR *work; Line 50  unsigned short FAR *work;
     unsigned fill;              /* index for replicating entries */      unsigned fill;              /* index for replicating entries */
     unsigned low;               /* low bits for current root entry */      unsigned low;               /* low bits for current root entry */
     unsigned mask;              /* mask for low root bits */      unsigned mask;              /* mask for low root bits */
    code this;                  /* table entry for duplication */    code here;                  /* table entry for duplication */
     code FAR *next;             /* next available space in table */      code FAR *next;             /* next available space in table */
     const unsigned short FAR *base;     /* base value table to use */      const unsigned short FAR *base;     /* base value table to use */
     const unsigned short FAR *extra;    /* extra bits table to use */      const unsigned short FAR *extra;    /* extra bits table to use */
Line 62  unsigned short FAR *work; Line 62  unsigned short FAR *work;
         35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};          35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
     static const unsigned short lext[31] = { /* Length codes 257..285 extra */      static const unsigned short lext[31] = { /* Length codes 257..285 extra */
         16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,          16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};        19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 72, 78};
     static const unsigned short dbase[32] = { /* Distance codes 0..29 base */      static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
         1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,          1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
         257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,          257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
Line 115  unsigned short FAR *work; Line 115  unsigned short FAR *work;
         if (count[max] != 0) break;          if (count[max] != 0) break;
     if (root > max) root = max;      if (root > max) root = max;
     if (max == 0) {                     /* no symbols to code at all */      if (max == 0) {                     /* no symbols to code at all */
        this.op = (unsigned char)64;    /* invalid code marker */        here.op = (unsigned char)64;    /* invalid code marker */
        this.bits = (unsigned char)1;        here.bits = (unsigned char)1;
        this.val = (unsigned short)0;        here.val = (unsigned short)0;
        *(*table)++ = this;             /* make a table to force an error */        *(*table)++ = here;             /* make a table to force an error */
        *(*table)++ = this;        *(*table)++ = here;
         *bits = 1;          *bits = 1;
         return 0;     /* no symbols, but wait for decoding to report error */          return 0;     /* no symbols, but wait for decoding to report error */
     }      }
    for (min = 1; min <= MAXBITS; min++)    for (min = 1; min < max; min++)
         if (count[min] != 0) break;          if (count[min] != 0) break;
     if (root < min) root = min;      if (root < min) root = min;
   
Line 166  unsigned short FAR *work; Line 166  unsigned short FAR *work;
        entered in the tables.         entered in the tables.
   
        used keeps track of how many table entries have been allocated from the         used keeps track of how many table entries have been allocated from the
       provided *table space.  It is checked when a LENS table is being made       provided *table space.  It is checked for LENS and DIST tables against
       against the space in *table, ENOUGH, minus the maximum space needed by       the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in
       the worst case distance code, MAXD.  This should never happen, but the       the initial root table size constants.  See the comments in inftrees.h
       sufficiency of ENOUGH has not been proven exhaustively, hence the check.       for more information.
       This assumes that when type == LENS, bits == 9. 
   
        sym increments through all symbols, and the loop terminates when         sym increments through all symbols, and the loop terminates when
        all codes of length max, i.e. all codes, have been processed.  This         all codes of length max, i.e. all codes, have been processed.  This
Line 209  unsigned short FAR *work; Line 208  unsigned short FAR *work;
     mask = used - 1;            /* mask for comparing low */      mask = used - 1;            /* mask for comparing low */
   
     /* check available table space */      /* check available table space */
    if (type == LENS && used >= ENOUGH - MAXD)    if ((type == LENS && used > ENOUGH_LENS) ||
         (type == DISTS && used > ENOUGH_DISTS))
         return 1;          return 1;
   
     /* process all codes and make table entries */      /* process all codes and make table entries */
     for (;;) {      for (;;) {
         /* create table entry */          /* create table entry */
        this.bits = (unsigned char)(len - drop);        here.bits = (unsigned char)(len - drop);
         if ((int)(work[sym]) < end) {          if ((int)(work[sym]) < end) {
            this.op = (unsigned char)0;            here.op = (unsigned char)0;
            this.val = work[sym];            here.val = work[sym];
         }          }
         else if ((int)(work[sym]) > end) {          else if ((int)(work[sym]) > end) {
            this.op = (unsigned char)(extra[work[sym]]);            here.op = (unsigned char)(extra[work[sym]]);
            this.val = base[work[sym]];            here.val = base[work[sym]];
         }          }
         else {          else {
            this.op = (unsigned char)(32 + 64);         /* end of block */            here.op = (unsigned char)(32 + 64);         /* end of block */
            this.val = 0;            here.val = 0;
         }          }
   
         /* replicate for those indices with low len bits equal to huff */          /* replicate for those indices with low len bits equal to huff */
Line 235  unsigned short FAR *work; Line 235  unsigned short FAR *work;
         min = fill;                 /* save offset to next table */          min = fill;                 /* save offset to next table */
         do {          do {
             fill -= incr;              fill -= incr;
            next[(huff >> drop) + fill] = this;            next[(huff >> drop) + fill] = here;
         } while (fill != 0);          } while (fill != 0);
   
         /* backwards increment the len-bit code huff */          /* backwards increment the len-bit code huff */
Line 277  unsigned short FAR *work; Line 277  unsigned short FAR *work;
   
             /* check for enough space */              /* check for enough space */
             used += 1U << curr;              used += 1U << curr;
            if (type == LENS && used >= ENOUGH - MAXD)            if ((type == LENS && used > ENOUGH_LENS) ||
                 (type == DISTS && used > ENOUGH_DISTS))
                 return 1;                  return 1;
   
             /* point entry in root table to sub-table */              /* point entry in root table to sub-table */
Line 288  unsigned short FAR *work; Line 289  unsigned short FAR *work;
         }          }
     }      }
   
    /*    /* fill in remaining table entry if code is incomplete (guaranteed to have
       Fill in rest of table for incomplete codes.  This loop is similar to the       at most one remaining entry, since if the code is incomplete, the
       loop above in incrementing huff for table indices.  It is assumed that       maximum code length that was allowed to get this far is one bit) */
       len is equal to curr + drop, so there is no loop needed to increment    if (huff != 0) {
       through high index bits.  When the current sub-table is filled, the loop        here.op = (unsigned char)64;            /* invalid code marker */
       drops back to the root table to fill in any remaining entries there.        here.bits = (unsigned char)(len - drop);
     */        here.val = (unsigned short)0;
    this.op = (unsigned char)64;                /* invalid code marker */        next[huff] = here;
    this.bits = (unsigned char)(len - drop); 
    this.val = (unsigned short)0; 
    while (huff != 0) { 
        /* when done with sub-table, drop back to root table */ 
        if (drop != 0 && (huff & mask) != low) { 
            drop = 0; 
            len = root; 
            next = *table; 
            this.bits = (unsigned char)len; 
        } 
 
        /* put invalid code marker in table */ 
        next[huff >> drop] = this; 
 
        /* backwards increment the len-bit code huff */ 
        incr = 1U << (len - 1); 
        while (huff & incr) 
            incr >>= 1; 
        if (incr != 0) { 
            huff &= incr - 1; 
            huff += incr; 
        } 
        else 
            huff = 0; 
     }      }
   
     /* set return parameters */      /* set return parameters */

Removed from v.1.1.1.1  
changed lines
  Added in v.1.1.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>