diff options
-rw-r--r-- | archival/libunarchive/decompress_unzip.c | 112 |
1 files changed, 56 insertions, 56 deletions
diff --git a/archival/libunarchive/decompress_unzip.c b/archival/libunarchive/decompress_unzip.c index 83261de6d..b4d62f16c 100644 --- a/archival/libunarchive/decompress_unzip.c +++ b/archival/libunarchive/decompress_unzip.c | |||
@@ -50,7 +50,7 @@ off_t gunzip_bytes_out; /* number of output bytes */ | |||
50 | uint32_t gunzip_crc; | 50 | uint32_t gunzip_crc; |
51 | 51 | ||
52 | static int gunzip_src_fd; | 52 | static int gunzip_src_fd; |
53 | static unsigned int gunzip_outbuf_count; /* bytes in output buffer */ | 53 | static unsigned gunzip_outbuf_count; /* bytes in output buffer */ |
54 | 54 | ||
55 | /* gunzip_window size--must be a power of two, and | 55 | /* gunzip_window size--must be a power of two, and |
56 | * at least 32K for zip's deflate method */ | 56 | * at least 32K for zip's deflate method */ |
@@ -64,14 +64,14 @@ static uint32_t *gunzip_crc_table; | |||
64 | #define N_MAX 288 /* maximum number of codes in any set */ | 64 | #define N_MAX 288 /* maximum number of codes in any set */ |
65 | 65 | ||
66 | /* bitbuffer */ | 66 | /* bitbuffer */ |
67 | static unsigned int gunzip_bb; /* bit buffer */ | 67 | static unsigned gunzip_bb; /* bit buffer */ |
68 | static unsigned char gunzip_bk; /* bits in bit buffer */ | 68 | static unsigned char gunzip_bk; /* bits in bit buffer */ |
69 | 69 | ||
70 | /* These control the size of the bytebuffer */ | 70 | /* These control the size of the bytebuffer */ |
71 | static unsigned int bytebuffer_max = 0x8000; | 71 | static unsigned bytebuffer_max = 0x8000; |
72 | static unsigned char *bytebuffer = NULL; | 72 | static unsigned char *bytebuffer = NULL; |
73 | static unsigned int bytebuffer_offset = 0; | 73 | static unsigned bytebuffer_offset = 0; |
74 | static unsigned int bytebuffer_size = 0; | 74 | static unsigned bytebuffer_size = 0; |
75 | 75 | ||
76 | static const unsigned short mask_bits[] = { | 76 | static const unsigned short mask_bits[] = { |
77 | 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, | 77 | 0x0000, 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff, |
@@ -109,7 +109,7 @@ static const unsigned char border[] = { | |||
109 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 | 109 | 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 |
110 | }; | 110 | }; |
111 | 111 | ||
112 | static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current, const unsigned int required) | 112 | static unsigned fill_bitbuffer(unsigned bitbuffer, unsigned *current, const unsigned required) |
113 | { | 113 | { |
114 | while (*current < required) { | 114 | while (*current < required) { |
115 | if (bytebuffer_offset >= bytebuffer_size) { | 115 | if (bytebuffer_offset >= bytebuffer_size) { |
@@ -121,7 +121,7 @@ static unsigned int fill_bitbuffer(unsigned int bitbuffer, unsigned int *current | |||
121 | bytebuffer_size += 4; | 121 | bytebuffer_size += 4; |
122 | bytebuffer_offset = 4; | 122 | bytebuffer_offset = 4; |
123 | } | 123 | } |
124 | bitbuffer |= ((unsigned int) bytebuffer[bytebuffer_offset]) << *current; | 124 | bitbuffer |= ((unsigned) bytebuffer[bytebuffer_offset]) << *current; |
125 | bytebuffer_offset++; | 125 | bytebuffer_offset++; |
126 | *current += 8; | 126 | *current += 8; |
127 | } | 127 | } |
@@ -164,9 +164,9 @@ static int huft_free(huft_t * t) | |||
164 | * m: maximum lookup bits, returns actual | 164 | * m: maximum lookup bits, returns actual |
165 | */ | 165 | */ |
166 | static | 166 | static |
167 | int huft_build(unsigned int *b, const unsigned int n, | 167 | int huft_build(unsigned *b, const unsigned n, |
168 | const unsigned int s, const unsigned short *d, | 168 | const unsigned s, const unsigned short *d, |
169 | const unsigned char *e, huft_t ** t, unsigned int *m) | 169 | const unsigned char *e, huft_t ** t, unsigned *m) |
170 | { | 170 | { |
171 | unsigned a; /* counter for codes of length k */ | 171 | unsigned a; /* counter for codes of length k */ |
172 | unsigned c[BMAX + 1]; /* bit length count table */ | 172 | unsigned c[BMAX + 1]; /* bit length count table */ |
@@ -338,17 +338,17 @@ int huft_build(unsigned int *b, const unsigned int n, | |||
338 | * tl, td: literal/length and distance decoder tables | 338 | * tl, td: literal/length and distance decoder tables |
339 | * bl, bd: number of bits decoded by tl[] and td[] | 339 | * bl, bd: number of bits decoded by tl[] and td[] |
340 | */ | 340 | */ |
341 | static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned int my_bl, const unsigned int my_bd, int setup) | 341 | static int inflate_codes(huft_t * my_tl, huft_t * my_td, const unsigned my_bl, const unsigned my_bd, int setup) |
342 | { | 342 | { |
343 | static unsigned int e; /* table entry flag/number of extra bits */ | 343 | static unsigned e; /* table entry flag/number of extra bits */ |
344 | static unsigned int n, d; /* length and index for copy */ | 344 | static unsigned n, d; /* length and index for copy */ |
345 | static unsigned int w; /* current gunzip_window position */ | 345 | static unsigned w; /* current gunzip_window position */ |
346 | static huft_t *t; /* pointer to table entry */ | 346 | static huft_t *t; /* pointer to table entry */ |
347 | static unsigned int ml, md; /* masks for bl and bd bits */ | 347 | static unsigned ml, md; /* masks for bl and bd bits */ |
348 | static unsigned int b; /* bit buffer */ | 348 | static unsigned b; /* bit buffer */ |
349 | static unsigned int k; /* number of bits in bit buffer */ | 349 | static unsigned k; /* number of bits in bit buffer */ |
350 | static huft_t *tl, *td; | 350 | static huft_t *tl, *td; |
351 | static unsigned int bl, bd; | 351 | static unsigned bl, bd; |
352 | static int resumeCopy = 0; | 352 | static int resumeCopy = 0; |
353 | 353 | ||
354 | if (setup) { // 1st time we are called, copy in variables | 354 | if (setup) { // 1st time we are called, copy in variables |
@@ -471,7 +471,7 @@ do_copy: do { | |||
471 | 471 | ||
472 | static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup) | 472 | static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup) |
473 | { | 473 | { |
474 | static unsigned int n, b_stored, k_stored, w; | 474 | static unsigned n, b_stored, k_stored, w; |
475 | if (setup) { | 475 | if (setup) { |
476 | n = my_n; | 476 | n = my_n; |
477 | b_stored = my_b_stored; | 477 | b_stored = my_b_stored; |
@@ -513,8 +513,8 @@ static int inflate_stored(int my_n, int my_b_stored, int my_k_stored, int setup) | |||
513 | static int inflate_block(int *e) | 513 | static int inflate_block(int *e) |
514 | { | 514 | { |
515 | unsigned t; /* block type */ | 515 | unsigned t; /* block type */ |
516 | unsigned int b; /* bit buffer */ | 516 | unsigned b; /* bit buffer */ |
517 | unsigned int k; /* number of bits in bit buffer */ | 517 | unsigned k; /* number of bits in bit buffer */ |
518 | 518 | ||
519 | /* make local bit buffer */ | 519 | /* make local bit buffer */ |
520 | 520 | ||
@@ -541,9 +541,9 @@ static int inflate_block(int *e) | |||
541 | switch (t) { | 541 | switch (t) { |
542 | case 0: /* Inflate stored */ | 542 | case 0: /* Inflate stored */ |
543 | { | 543 | { |
544 | unsigned int n; /* number of bytes in block */ | 544 | unsigned n; /* number of bytes in block */ |
545 | unsigned int b_stored; /* bit buffer */ | 545 | unsigned b_stored; /* bit buffer */ |
546 | unsigned int k_stored; /* number of bits in bit buffer */ | 546 | unsigned k_stored; /* number of bits in bit buffer */ |
547 | 547 | ||
548 | /* make local copies of globals */ | 548 | /* make local copies of globals */ |
549 | b_stored = gunzip_bb; /* initialize bit buffer */ | 549 | b_stored = gunzip_bb; /* initialize bit buffer */ |
@@ -579,9 +579,9 @@ static int inflate_block(int *e) | |||
579 | int i; /* temporary variable */ | 579 | int i; /* temporary variable */ |
580 | huft_t *tl; /* literal/length code table */ | 580 | huft_t *tl; /* literal/length code table */ |
581 | huft_t *td; /* distance code table */ | 581 | huft_t *td; /* distance code table */ |
582 | unsigned int bl; /* lookup bits for tl */ | 582 | unsigned bl; /* lookup bits for tl */ |
583 | unsigned int bd; /* lookup bits for td */ | 583 | unsigned bd; /* lookup bits for td */ |
584 | unsigned int l[288]; /* length list for huft_build */ | 584 | unsigned l[288]; /* length list for huft_build */ |
585 | 585 | ||
586 | /* set up literal table */ | 586 | /* set up literal table */ |
587 | for (i = 0; i < 144; i++) { | 587 | for (i = 0; i < 144; i++) { |
@@ -625,20 +625,20 @@ static int inflate_block(int *e) | |||
625 | 625 | ||
626 | huft_t *tl; /* literal/length code table */ | 626 | huft_t *tl; /* literal/length code table */ |
627 | huft_t *td; /* distance code table */ | 627 | huft_t *td; /* distance code table */ |
628 | unsigned int i; /* temporary variables */ | 628 | unsigned i; /* temporary variables */ |
629 | unsigned int j; | 629 | unsigned j; |
630 | unsigned int l; /* last length */ | 630 | unsigned l; /* last length */ |
631 | unsigned int m; /* mask for bit lengths table */ | 631 | unsigned m; /* mask for bit lengths table */ |
632 | unsigned int n; /* number of lengths to get */ | 632 | unsigned n; /* number of lengths to get */ |
633 | unsigned int bl; /* lookup bits for tl */ | 633 | unsigned bl; /* lookup bits for tl */ |
634 | unsigned int bd; /* lookup bits for td */ | 634 | unsigned bd; /* lookup bits for td */ |
635 | unsigned int nb; /* number of bit length codes */ | 635 | unsigned nb; /* number of bit length codes */ |
636 | unsigned int nl; /* number of literal/length codes */ | 636 | unsigned nl; /* number of literal/length codes */ |
637 | unsigned int nd; /* number of distance codes */ | 637 | unsigned nd; /* number of distance codes */ |
638 | 638 | ||
639 | unsigned int ll[286 + 30]; /* literal/length and distance code lengths */ | 639 | unsigned ll[286 + 30]; /* literal/length and distance code lengths */ |
640 | unsigned int b_dynamic; /* bit buffer */ | 640 | unsigned b_dynamic; /* bit buffer */ |
641 | unsigned int k_dynamic; /* number of bits in bit buffer */ | 641 | unsigned k_dynamic; /* number of bits in bit buffer */ |
642 | 642 | ||
643 | /* make local bit buffer */ | 643 | /* make local bit buffer */ |
644 | b_dynamic = gunzip_bb; | 644 | b_dynamic = gunzip_bb; |
@@ -646,17 +646,17 @@ static int inflate_block(int *e) | |||
646 | 646 | ||
647 | /* read in table lengths */ | 647 | /* read in table lengths */ |
648 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 5); | 648 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 5); |
649 | nl = 257 + ((unsigned int) b_dynamic & 0x1f); /* number of literal/length codes */ | 649 | nl = 257 + ((unsigned) b_dynamic & 0x1f); /* number of literal/length codes */ |
650 | 650 | ||
651 | b_dynamic >>= 5; | 651 | b_dynamic >>= 5; |
652 | k_dynamic -= 5; | 652 | k_dynamic -= 5; |
653 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 5); | 653 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 5); |
654 | nd = 1 + ((unsigned int) b_dynamic & 0x1f); /* number of distance codes */ | 654 | nd = 1 + ((unsigned) b_dynamic & 0x1f); /* number of distance codes */ |
655 | 655 | ||
656 | b_dynamic >>= 5; | 656 | b_dynamic >>= 5; |
657 | k_dynamic -= 5; | 657 | k_dynamic -= 5; |
658 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 4); | 658 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 4); |
659 | nb = 4 + ((unsigned int) b_dynamic & 0xf); /* number of bit length codes */ | 659 | nb = 4 + ((unsigned) b_dynamic & 0xf); /* number of bit length codes */ |
660 | 660 | ||
661 | b_dynamic >>= 4; | 661 | b_dynamic >>= 4; |
662 | k_dynamic -= 4; | 662 | k_dynamic -= 4; |
@@ -667,7 +667,7 @@ static int inflate_block(int *e) | |||
667 | /* read in bit-length-code lengths */ | 667 | /* read in bit-length-code lengths */ |
668 | for (j = 0; j < nb; j++) { | 668 | for (j = 0; j < nb; j++) { |
669 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 3); | 669 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 3); |
670 | ll[border[j]] = (unsigned int) b_dynamic & 7; | 670 | ll[border[j]] = (unsigned) b_dynamic & 7; |
671 | b_dynamic >>= 3; | 671 | b_dynamic >>= 3; |
672 | k_dynamic -= 3; | 672 | k_dynamic -= 3; |
673 | } | 673 | } |
@@ -689,9 +689,9 @@ static int inflate_block(int *e) | |||
689 | n = nl + nd; | 689 | n = nl + nd; |
690 | m = mask_bits[bl]; | 690 | m = mask_bits[bl]; |
691 | i = l = 0; | 691 | i = l = 0; |
692 | while ((unsigned int) i < n) { | 692 | while ((unsigned) i < n) { |
693 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, (unsigned int)bl); | 693 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, (unsigned)bl); |
694 | j = (td = tl + ((unsigned int) b_dynamic & m))->b; | 694 | j = (td = tl + ((unsigned) b_dynamic & m))->b; |
695 | b_dynamic >>= j; | 695 | b_dynamic >>= j; |
696 | k_dynamic -= j; | 696 | k_dynamic -= j; |
697 | j = td->v.n; | 697 | j = td->v.n; |
@@ -699,10 +699,10 @@ static int inflate_block(int *e) | |||
699 | ll[i++] = l = j; /* save last length in l */ | 699 | ll[i++] = l = j; /* save last length in l */ |
700 | } else if (j == 16) { /* repeat last length 3 to 6 times */ | 700 | } else if (j == 16) { /* repeat last length 3 to 6 times */ |
701 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 2); | 701 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 2); |
702 | j = 3 + ((unsigned int) b_dynamic & 3); | 702 | j = 3 + ((unsigned) b_dynamic & 3); |
703 | b_dynamic >>= 2; | 703 | b_dynamic >>= 2; |
704 | k_dynamic -= 2; | 704 | k_dynamic -= 2; |
705 | if ((unsigned int) i + j > n) { | 705 | if ((unsigned) i + j > n) { |
706 | return 1; | 706 | return 1; |
707 | } | 707 | } |
708 | while (j--) { | 708 | while (j--) { |
@@ -710,10 +710,10 @@ static int inflate_block(int *e) | |||
710 | } | 710 | } |
711 | } else if (j == 17) { /* 3 to 10 zero length codes */ | 711 | } else if (j == 17) { /* 3 to 10 zero length codes */ |
712 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 3); | 712 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 3); |
713 | j = 3 + ((unsigned int) b_dynamic & 7); | 713 | j = 3 + ((unsigned) b_dynamic & 7); |
714 | b_dynamic >>= 3; | 714 | b_dynamic >>= 3; |
715 | k_dynamic -= 3; | 715 | k_dynamic -= 3; |
716 | if ((unsigned int) i + j > n) { | 716 | if ((unsigned) i + j > n) { |
717 | return 1; | 717 | return 1; |
718 | } | 718 | } |
719 | while (j--) { | 719 | while (j--) { |
@@ -722,10 +722,10 @@ static int inflate_block(int *e) | |||
722 | l = 0; | 722 | l = 0; |
723 | } else { /* j == 18: 11 to 138 zero length codes */ | 723 | } else { /* j == 18: 11 to 138 zero length codes */ |
724 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 7); | 724 | b_dynamic = fill_bitbuffer(b_dynamic, &k_dynamic, 7); |
725 | j = 11 + ((unsigned int) b_dynamic & 0x7f); | 725 | j = 11 + ((unsigned) b_dynamic & 0x7f); |
726 | b_dynamic >>= 7; | 726 | b_dynamic >>= 7; |
727 | k_dynamic -= 7; | 727 | k_dynamic -= 7; |
728 | if ((unsigned int) i + j > n) { | 728 | if ((unsigned) i + j > n) { |
729 | return 1; | 729 | return 1; |
730 | } | 730 | } |
731 | while (j--) { | 731 | while (j--) { |
@@ -824,7 +824,7 @@ static int inflate_get_next_window(void) | |||
824 | } | 824 | } |
825 | 825 | ||
826 | /* Initialise bytebuffer, be careful not to overfill the buffer */ | 826 | /* Initialise bytebuffer, be careful not to overfill the buffer */ |
827 | void inflate_init(unsigned int bufsize) | 827 | void inflate_init(unsigned bufsize) |
828 | { | 828 | { |
829 | /* Set the bytebuffer size, default is same as gunzip_wsize */ | 829 | /* Set the bytebuffer size, default is same as gunzip_wsize */ |
830 | bytebuffer_max = bufsize + 8; | 830 | bytebuffer_max = bufsize + 8; |
@@ -892,7 +892,7 @@ USE_DESKTOP(long long) int | |||
892 | inflate_gunzip(int in, int out) | 892 | inflate_gunzip(int in, int out) |
893 | { | 893 | { |
894 | uint32_t stored_crc = 0; | 894 | uint32_t stored_crc = 0; |
895 | unsigned int count; | 895 | unsigned count; |
896 | USE_DESKTOP(long long total = )inflate_unzip(in, out); | 896 | USE_DESKTOP(long long total = )inflate_unzip(in, out); |
897 | 897 | ||
898 | USE_DESKTOP(if (total < 0) return total;) | 898 | USE_DESKTOP(if (total < 0) return total;) |