summaryrefslogtreecommitdiff
path: root/contrib/puff
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:34:30 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:34:30 -0700
commit7147f24cd7b27dd95f6e841851a111cb311a9c07 (patch)
tree1492bbbb8828513c8ad129adff414b2ba724aa03 /contrib/puff
parent05d47d2627a68a15ba23fb10b17fbc73551aeec1 (diff)
downloadzlib-1.2.4.2.tar.gz
zlib-1.2.4.2.tar.bz2
zlib-1.2.4.2.zip
zlib 1.2.4.2v1.2.4.2
Diffstat (limited to 'contrib/puff')
-rw-r--r--contrib/puff/puff.c29
-rw-r--r--contrib/puff/puff.h4
2 files changed, 23 insertions, 10 deletions
diff --git a/contrib/puff/puff.c b/contrib/puff/puff.c
index df5b79f..650694e 100644
--- a/contrib/puff/puff.c
+++ b/contrib/puff/puff.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * puff.c 2 * puff.c
3 * Copyright (C) 2002-2008 Mark Adler 3 * Copyright (C) 2002-2010 Mark Adler
4 * For conditions of distribution and use, see copyright notice in puff.h 4 * For conditions of distribution and use, see copyright notice in puff.h
5 * version 2.0, 25 Jul 2008 5 * version 2.1, 4 Apr 2010
6 * 6 *
7 * puff.c is a simple inflate written to be an unambiguous way to specify the 7 * puff.c is a simple inflate written to be an unambiguous way to specify the
8 * deflate format. It is not written for speed but rather simplicity. As a 8 * deflate format. It is not written for speed but rather simplicity. As a
@@ -67,6 +67,8 @@
67 * - Add option in TEST code for puff to write the data 67 * - Add option in TEST code for puff to write the data
68 * - Add option in TEST code to skip input bytes 68 * - Add option in TEST code to skip input bytes
69 * - Allow TEST code to read from piped stdin 69 * - Allow TEST code to read from piped stdin
70 * 2.1 4 Apr 2010 - Avoid variable initialization for happier compilers
71 * - Avoid unsigned comparisons for even happier compilers
70 */ 72 */
71 73
72#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */ 74#include <setjmp.h> /* for setjmp(), longjmp(), and jmp_buf */
@@ -516,8 +518,7 @@ local int fixed(struct state *s)
516 static int virgin = 1; 518 static int virgin = 1;
517 static short lencnt[MAXBITS+1], lensym[FIXLCODES]; 519 static short lencnt[MAXBITS+1], lensym[FIXLCODES];
518 static short distcnt[MAXBITS+1], distsym[MAXDCODES]; 520 static short distcnt[MAXBITS+1], distsym[MAXDCODES];
519 static struct huffman lencode = {lencnt, lensym}; 521 static struct huffman lencode, distcode;
520 static struct huffman distcode = {distcnt, distsym};
521 522
522 /* build fixed huffman tables if first call (may not be thread safe) */ 523 /* build fixed huffman tables if first call (may not be thread safe) */
523 if (virgin) { 524 if (virgin) {
@@ -540,6 +541,12 @@ local int fixed(struct state *s)
540 lengths[symbol] = 5; 541 lengths[symbol] = 5;
541 construct(&distcode, lengths, MAXDCODES); 542 construct(&distcode, lengths, MAXDCODES);
542 543
544 /* construct lencode and distcode */
545 lencode.count = lencnt;
546 lencode.symbol = lensym;
547 distcode.count = distcnt;
548 distcode.symbol = distsym;
549
543 /* do this just once */ 550 /* do this just once */
544 virgin = 0; 551 virgin = 0;
545 } 552 }
@@ -643,11 +650,16 @@ local int dynamic(struct state *s)
643 short lengths[MAXCODES]; /* descriptor code lengths */ 650 short lengths[MAXCODES]; /* descriptor code lengths */
644 short lencnt[MAXBITS+1], lensym[MAXLCODES]; /* lencode memory */ 651 short lencnt[MAXBITS+1], lensym[MAXLCODES]; /* lencode memory */
645 short distcnt[MAXBITS+1], distsym[MAXDCODES]; /* distcode memory */ 652 short distcnt[MAXBITS+1], distsym[MAXDCODES]; /* distcode memory */
646 struct huffman lencode = {lencnt, lensym}; /* length code */ 653 struct huffman lencode, distcode; /* length and distance codes */
647 struct huffman distcode = {distcnt, distsym}; /* distance code */
648 static const short order[19] = /* permutation of code length codes */ 654 static const short order[19] = /* permutation of code length codes */
649 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; 655 {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
650 656
657 /* construct lencode and distcode */
658 lencode.count = lencnt;
659 lencode.symbol = lensym;
660 distcode.count = distcnt;
661 distcode.symbol = distsym;
662
651 /* get number of lengths in each table, check lengths */ 663 /* get number of lengths in each table, check lengths */
652 nlen = bits(s, 5) + 257; 664 nlen = bits(s, 5) + 257;
653 ndist = bits(s, 5) + 1; 665 ndist = bits(s, 5) + 1;
@@ -869,7 +881,8 @@ local void *load(char *name, size_t *len)
869 881
870int main(int argc, char **argv) 882int main(int argc, char **argv)
871{ 883{
872 int ret, skip = 0, put = 0; 884 int ret, put = 0;
885 unsigned skip = 0;
873 char *arg, *name = NULL; 886 char *arg, *name = NULL;
874 unsigned char *source = NULL, *dest; 887 unsigned char *source = NULL, *dest;
875 size_t len = 0; 888 size_t len = 0;
@@ -881,7 +894,7 @@ int main(int argc, char **argv)
881 if (arg[1] == 'w' && arg[2] == 0) 894 if (arg[1] == 'w' && arg[2] == 0)
882 put = 1; 895 put = 1;
883 else if (arg[1] >= '0' && arg[1] <= '9') 896 else if (arg[1] >= '0' && arg[1] <= '9')
884 skip = atoi(arg + 1); 897 skip = (unsigned)atoi(arg + 1);
885 else { 898 else {
886 fprintf(stderr, "invalid option %s\n", arg); 899 fprintf(stderr, "invalid option %s\n", arg);
887 return 3; 900 return 3;
diff --git a/contrib/puff/puff.h b/contrib/puff/puff.h
index 8d7f5f8..88d1b38 100644
--- a/contrib/puff/puff.h
+++ b/contrib/puff/puff.h
@@ -1,6 +1,6 @@
1/* puff.h 1/* puff.h
2 Copyright (C) 2002-2008 Mark Adler, all rights reserved 2 Copyright (C) 2002-2010 Mark Adler, all rights reserved
3 version 1.9, 10 Jan 2008 3 version 2.1, 4 Apr 2010
4 4
5 This software is provided 'as-is', without any express or implied 5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the author be held liable for any damages 6 warranty. In no event will the author be held liable for any damages