--- pgp/src/zinflate.c 2018/04/24 16:37:53 1.1 +++ pgp/src/zinflate.c 2018/04/24 16:41:13 1.1.1.4 @@ -130,6 +130,7 @@ */ #include "zunzip.h" +#include "exitpgp.h" #define OF __ #ifndef WSIZE @@ -166,7 +167,7 @@ struct huft { /* Function prototypes */ int huft_build OF((unsigned *, unsigned, unsigned, UWORD *, UWORD *, - struct huft **, int *)); + struct huft **, int *)); int huft_free OF((struct huft *)); void flush OF((unsigned)); int inflate_codes OF((struct huft *, struct huft *, int, int)); @@ -175,7 +176,7 @@ int inflate_fixed OF((void)); int inflate_dynamic OF((void)); int inflate_block OF((int *)); int inflate_entry OF((void)); -void inflate OF((void)); +int inflate OF((void)); /* The inflate algorithm uses a sliding 32K byte window on the uncompressed @@ -204,7 +205,7 @@ static UWORD cpdist[] = { /* Copy 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577}; static UWORD cpdext[] = { /* Extra bits for distance codes */ - 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, + 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13}; @@ -242,8 +243,18 @@ ULONG bb; /* bit b unsigned bk; /* bits in bit buffer */ UWORD bytebuf; +#if 0 #define NEXTBYTE (ReadByte(&bytebuf), bytebuf) #define NEEDBITS(n) {while(k<(n)){b|=((ULONG)NEXTBYTE)<>=(n);k-=(n);} @@ -403,7 +414,7 @@ int *m; /* maximum looku z = (z = g - w) > l ? l : z; /* upper limit on table size */ if ((f = 1 << (j = k - w)) > a + 1) /* try a k-w bit table */ { /* too few codes for k-w bit table */ - f -= a + 1; /* deduct codes from patterns left */ + f -= a + 1; /* deduct codes from patterns left */ xp = c + k; while (++j < z) /* try smaller tables up to z bits */ { @@ -516,7 +527,11 @@ unsigned w; /* number of byt memcpy(outptr, p, n); /* try to fill up buffer */ outptr += n; if ((outcnt += n) == OUTBUFSIZ) - FlushOutput(); /* if full, empty */ + if (FlushOutput()) /* if full, empty */ + { + fprintf(stderr, "\nWrite error.\n"); + exitPGP(1); + } p += n; w -= n; } @@ -603,7 +618,7 @@ int bl, bd; /* number of bit { memcpy(slide + w, slide + d, e); w += e; - d += e; + d += e; } else /* do it slow to avoid memcpy() overlap */ #endif /* !NOMEMCPY */ @@ -966,18 +981,25 @@ int inflate_entry() } -void inflate() +int inflate() /* ignore the return code for now ... */ { + int status; + #ifdef DYN_ALLOC - if (window == NULL) { - window = (char*) calloc((unsigned)WSIZE, 2*sizeof(char)); + window = (char*) calloc((unsigned)WSIZE, 2*sizeof(char)); /* Note that inflate only needs WSIZE bytes, but the window * array is shared with deflate, which needs 2*WISZE bytes. */ - if (window==NULL) err(4, ""); - } + if (window==NULL) err(4, ""); +#endif + + status = inflate_entry(); + +#ifdef DYN_ALLOC + free(window); + window = NULL; #endif - inflate_entry(); + return status; }