From 62c6d5ec70f0426f19dfb75a3b48f1b80094ee70 Mon Sep 17 00:00:00 2001 From: Hans Kristian Rosbach Date: Sat, 16 May 2015 21:23:07 +0200 Subject: [PATCH] Replace unsigned short with uint16_t Conflicts: inflate.h inftrees.c inftrees.h match.c --- infback.c | 6 +++--- inflate.c | 6 +++--- inflate.h | 6 +++--- inftrees.c | 30 +++++++++++++++--------------- inftrees.h | 11 +++++------ match.c | 30 +++++++++++++++--------------- test/infcover.c | 4 ++-- 7 files changed, 46 insertions(+), 47 deletions(-) diff --git a/infback.c b/infback.c index 290e839d..08e77fa4 100644 --- a/infback.c +++ b/infback.c @@ -249,7 +249,7 @@ int ZEXPORT inflateBack(z_stream *strm, in_func in, void *in_desc, code last; /* parent table entry */ unsigned len; /* length to copy for repeats, bits to drop */ int ret; /* return code */ - static const unsigned short order[19] = /* permutation of code lengths */ + static const uint16_t order[19] = /* permutation of code lengths */ {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; /* Check that the strm exists and that the state was initialized */ @@ -360,7 +360,7 @@ int ZEXPORT inflateBack(z_stream *strm, in_func in, void *in_desc, state->have = 0; while (state->have < state->ncode) { NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); + state->lens[order[state->have++]] = (uint16_t)BITS(3); DROPBITS(3); } while (state->have < 19) @@ -422,7 +422,7 @@ int ZEXPORT inflateBack(z_stream *strm, in_func in, void *in_desc, break; } while (copy--) - state->lens[state->have++] = (unsigned short)len; + state->lens[state->have++] = (uint16_t)len; } } diff --git a/inflate.c b/inflate.c index a3a342f9..a63f699b 100644 --- a/inflate.c +++ b/inflate.c @@ -593,7 +593,7 @@ int ZEXPORT inflate(z_stream *strm, int flush) #ifdef GUNZIP unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ #endif - static const unsigned short order[19] = /* permutation of code lengths */ + static const uint16_t order[19] = /* permutation of code lengths */ {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || @@ -886,7 +886,7 @@ int ZEXPORT inflate(z_stream *strm, int flush) case LENLENS: while (state->have < state->ncode) { NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); + state->lens[order[state->have++]] = (uint16_t)BITS(3); DROPBITS(3); } while (state->have < 19) @@ -948,7 +948,7 @@ int ZEXPORT inflate(z_stream *strm, int flush) break; } while (copy--) - state->lens[state->have++] = (unsigned short)len; + state->lens[state->have++] = (uint16_t)len; } } diff --git a/inflate.h b/inflate.h index dbd26f0b..c6e7ff8e 100644 --- a/inflate.h +++ b/inflate.h @@ -112,9 +112,9 @@ struct inflate_state { unsigned nlen; /* number of length code lengths */ unsigned ndist; /* number of distance code lengths */ unsigned have; /* number of code lengths in lens[] */ - code *next; /* next available space in codes[] */ - unsigned short lens[320]; /* temporary storage for code lengths */ - unsigned short work[288]; /* work area for code table building */ + code *next; /* next available space in codes[] */ + uint16_t lens[320]; /* temporary storage for code lengths */ + uint16_t work[288]; /* work area for code table building */ code codes[ENOUGH]; /* space for code tables */ int sane; /* if false, allow invalid distance too far */ int back; /* bits back of last unprocessed length/lit */ diff --git a/inftrees.c b/inftrees.c index 48165963..bd651808 100644 --- a/inftrees.c +++ b/inftrees.c @@ -29,8 +29,8 @@ const char inflate_copyright[] = table index bits. It will differ if the request is greater than the longest code or if it is less than the shortest code. */ -int ZLIB_INTERNAL inflate_table(codetype type, unsigned short *lens, unsigned codes, - code * *table, unsigned *bits, unsigned short *work) +int ZLIB_INTERNAL inflate_table(codetype type, uint16_t *lens, unsigned codes, + code * *table, unsigned *bits, uint16_t *work) { unsigned len; /* a code's length in bits */ unsigned sym; /* index of code symbols */ @@ -46,23 +46,23 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short *lens, unsigned co unsigned low; /* low bits for current root entry */ unsigned mask; /* mask for low root bits */ code here; /* table entry for duplication */ - code *next; /* next available space in table */ - const unsigned short *base; /* base value table to use */ - const unsigned short *extra; /* extra bits table to use */ + code *next; /* next available space in table */ + const uint16_t *base; /* base value table to use */ + const uint16_t *extra; /* extra bits table to use */ int end; /* use base and extra for symbol > end */ - unsigned short count[MAXBITS+1]; /* number of codes of each length */ - unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ - static const unsigned short lbase[31] = { /* Length codes 257..285 base */ + uint16_t count[MAXBITS+1]; /* number of codes of each length */ + uint16_t offs[MAXBITS+1]; /* offsets in table for each length */ + static const uint16_t lbase[31] = { /* Length codes 257..285 base */ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 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 uint16_t lext[31] = { /* Length codes 257..285 extra */ 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, 72, 78}; - static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ + static const uint16_t dbase[32] = { /* Distance codes 0..29 base */ 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, 8193, 12289, 16385, 24577, 0, 0}; - static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ + static const uint16_t dext[32] = { /* Distance codes 0..29 extra */ 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 64, 64}; @@ -112,7 +112,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short *lens, unsigned co if (max == 0) { /* no symbols to code at all */ here.op = (unsigned char)64; /* invalid code marker */ here.bits = (unsigned char)1; - here.val = (unsigned short)0; + here.val = (uint16_t)0; *(*table)++ = here; /* make a table to force an error */ *(*table)++ = here; *bits = 1; @@ -139,7 +139,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short *lens, unsigned co /* sort symbols by length, by symbol order within each length */ for (sym = 0; sym < codes; sym++) - if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; + if (lens[sym] != 0) work[offs[lens[sym]]++] = (uint16_t)sym; /* Create and fill in decoding tables. In this loop, the table being @@ -280,7 +280,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short *lens, unsigned co low = huff & mask; (*table)[low].op = (unsigned char)curr; (*table)[low].bits = (unsigned char)root; - (*table)[low].val = (unsigned short)(next - *table); + (*table)[low].val = (uint16_t)(next - *table); } } @@ -290,7 +290,7 @@ int ZLIB_INTERNAL inflate_table(codetype type, unsigned short *lens, unsigned co if (huff != 0) { here.op = (unsigned char)64; /* invalid code marker */ here.bits = (unsigned char)(len - drop); - here.val = (unsigned short)0; + here.val = (uint16_t)0; next[huff] = here; } diff --git a/inftrees.h b/inftrees.h index a568d409..f266235b 100644 --- a/inftrees.h +++ b/inftrees.h @@ -22,9 +22,9 @@ of a literal, the base length or distance, or the offset from the current table to the next table. Each entry is four bytes. */ typedef struct { - unsigned char op; /* operation, extra bits, table bits */ - unsigned char bits; /* bits in this part of the code */ - unsigned short val; /* offset in table or code value */ + unsigned char op; /* operation, extra bits, table bits */ + unsigned char bits; /* bits in this part of the code */ + uint16_t val; /* offset in table or code value */ } code; /* op values as set by inflate_table(): @@ -57,6 +57,5 @@ typedef enum { DISTS } codetype; -int ZLIB_INTERNAL inflate_table (codetype type, unsigned short *lens, - unsigned codes, code * *table, - unsigned *bits, unsigned short *work); +int ZLIB_INTERNAL inflate_table (codetype type, uint16_t *lens, unsigned codes, + code * *table, unsigned *bits, uint16_t *work); diff --git a/match.c b/match.c index 7a58b276..a56d1b74 100644 --- a/match.c +++ b/match.c @@ -156,7 +156,7 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) const unsigned wmask = s->w_mask; const Pos *prev = s->prev; - unsigned short scan_start, scan_end; + uint16_t scan_start, scan_end; unsigned chain_length; IPos limit; unsigned int len, best_len, nice_match; @@ -190,8 +190,8 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) scan = s->window + s->strstart; strend = s->window + s->strstart + MAX_MATCH - 1; - scan_start = *(unsigned short *)scan; - scan_end = *(unsigned short *)(scan + best_len-1); + scan_start = *(uint16_t *)scan; + scan_end = *(uint16_t *)(scan + best_len-1); Assert((unsigned long)s->strstart <= s->window_size - MIN_LOOKAHEAD, "need lookahead"); @@ -210,9 +210,9 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) * is limited to the lookahead, so the output of deflate is not * affected by the uninitialized values. */ - if (likely((*(unsigned short *)(match + best_len - 1) != scan_end))) + if (likely((*(uint16_t *)(match + best_len - 1) != scan_end))) continue; - if (*(unsigned short *)match != scan_start) + if (*(uint16_t *)match != scan_start) continue; /* It is not necessary to compare scan[2] and match[2] since @@ -230,10 +230,10 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) match++; do { - } while (*(unsigned short *)(scan += 2)== *(unsigned short *)(match += 2)&& - *(unsigned short *)(scan += 2)== *(unsigned short *)(match += 2)&& - *(unsigned short *)(scan += 2)== *(unsigned short *)(match += 2)&& - *(unsigned short *)(scan += 2)== *(unsigned short *)(match += 2)&& + } while (*(uint16_t *)(scan += 2)== *(uint16_t *)(match += 2)&& + *(uint16_t *)(scan += 2)== *(uint16_t *)(match += 2)&& + *(uint16_t *)(scan += 2)== *(uint16_t *)(match += 2)&& + *(uint16_t *)(scan += 2)== *(uint16_t *)(match += 2)&& scan < strend); /* @@ -251,7 +251,7 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) best_len = len; if (len >= nice_match) break; - scan_end = *(unsigned short *)(scan + best_len - 1); + scan_end = *(uint16_t *)(scan + best_len - 1); } else { /* * The probability of finding a match later if we here @@ -351,8 +351,8 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) uInt wmask = s->w_mask; register unsigned char *strend = s->window + s->strstart + MAX_MATCH; - register unsigned short scan_start = *(unsigned short*)scan; - register unsigned short scan_end = *(unsigned short*)(scan+best_len-1); + register uint16_t scan_start = *(uint16_t*)scan; + register uint16_t scan_end = *(uint16_t*)(scan+best_len-1); /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. * It is easy to get rid of this optimization if necessary. @@ -385,7 +385,7 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) int cont = 1; do { match = win + cur_match; - if (likely(*(unsigned short*)(match+best_len-1) != scan_end)) { + if (likely(*(uint16_t*)(match+best_len-1) != scan_end)) { if ((cur_match = prev[cur_match & wmask]) > limit && --chain_length != 0) { continue; @@ -398,7 +398,7 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) if (!cont) break; - if (*(unsigned short*)match != scan_start) + if (*(uint16_t*)match != scan_start) continue; /* It is not necessary to compare scan[2] and match[2] since they are @@ -439,7 +439,7 @@ ZLIB_INTERNAL unsigned longest_match(deflate_state *const s, IPos cur_match) s->match_start = cur_match; best_len = len; if (len >= nice_match) break; - scan_end = *(unsigned short*)(scan+best_len-1); + scan_end = *(uint16_t*)(scan+best_len-1); } else { /* * The probability of finding a match later if we here diff --git a/test/infcover.c b/test/infcover.c index 1786f047..fe4bf2de 100644 --- a/test/infcover.c +++ b/test/infcover.c @@ -631,13 +631,13 @@ static void cover_trees(void) { int ret; unsigned bits; - unsigned short lens[16], work[16]; + uint16_t lens[16], work[16]; code *next, table[ENOUGH_DISTS]; /* we need to call inflate_table() directly in order to manifest not- enough errors, since zlib insures that enough is always enough */ for (bits = 0; bits < 15; bits++) - lens[bits] = (unsigned short)(bits + 1); + lens[bits] = (uint16_t)(bits + 1); lens[15] = 15; next = table; bits = 15; -- 2.47.2