aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-06-10 15:08:44 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-06-10 15:08:44 +0000
commite8a0788b249cbac5bf5b2aa2d81bb8f6b29a7a4b (patch)
treefcdf3d51b6d60986b634c693d71355867bca82ff /archival
parentd4fea900bdb92d7bba71348a40cb00b6748a8ecc (diff)
downloadbusybox-w32-e8a0788b249cbac5bf5b2aa2d81bb8f6b29a7a4b.tar.gz
busybox-w32-e8a0788b249cbac5bf5b2aa2d81bb8f6b29a7a4b.tar.bz2
busybox-w32-e8a0788b249cbac5bf5b2aa2d81bb8f6b29a7a4b.zip
moved biggest stack buffers to malloc space, or made their size configurable
(8k of shell line edit buffer is an overkill) # make ARCH=i386 bloatcheck function old new delta read_line_input 3933 3967 +34 ifaddrlist 348 345 -3 do_loadfont 208 191 -17 edit_file 840 819 -21 .rodata 129112 129080 -32 uncompress 1305 1268 -37 loadfont_main 566 495 -71 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/6 up/down: 34/-181) Total: -147 bytes
Diffstat (limited to 'archival')
-rw-r--r--archival/libunarchive/decompress_uncompress.c98
1 files changed, 49 insertions, 49 deletions
diff --git a/archival/libunarchive/decompress_uncompress.c b/archival/libunarchive/decompress_uncompress.c
index ba73f1132..8c3c65d1a 100644
--- a/archival/libunarchive/decompress_uncompress.c
+++ b/archival/libunarchive/decompress_uncompress.c
@@ -7,7 +7,6 @@
7 * (see disclaimer below) 7 * (see disclaimer below)
8 */ 8 */
9 9
10
11/* (N)compress42.c - File compression ala IEEE Computer, Mar 1992. 10/* (N)compress42.c - File compression ala IEEE Computer, Mar 1992.
12 * 11 *
13 * Authors: 12 * Authors:
@@ -34,53 +33,48 @@
34#define OBUFSIZ 2048 33#define OBUFSIZ 2048
35 34
36/* Defines for third byte of header */ 35/* Defines for third byte of header */
37#define MAGIC_1 (char_type)'\037' /* First byte of compressed file */ 36#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */
38#define MAGIC_2 (char_type)'\235' /* Second byte of compressed file */ 37 /* Masks 0x20 and 0x40 are free. */
39#define BIT_MASK 0x1f /* Mask for 'number of compresssion bits' */ 38 /* I think 0x20 should mean that there is */
40 /* Masks 0x20 and 0x40 are free. */ 39 /* a fourth header byte (for expansion). */
41 /* I think 0x20 should mean that there is */ 40#define BLOCK_MODE 0x80 /* Block compression if table is full and */
42 /* a fourth header byte (for expansion). */ 41 /* compression rate is dropping flush tables */
43#define BLOCK_MODE 0x80 /* Block compresssion if table is full and */ 42 /* the next two codes should not be changed lightly, as they must not */
44 /* compression rate is dropping flush tables */ 43 /* lie within the contiguous general code space. */
45 /* the next two codes should not be changed lightly, as they must not */ 44#define FIRST 257 /* first free entry */
46 /* lie within the contiguous general code space. */ 45#define CLEAR 256 /* table clear output code */
47#define FIRST 257 /* first free entry */
48#define CLEAR 256 /* table clear output code */
49
50#define INIT_BITS 9 /* initial number of bits/code */
51
52 46
53/* machine variants which require cc -Dmachine: pdp11, z8000, DOS */ 47#define INIT_BITS 9 /* initial number of bits/code */
54#define FAST
55 48
56#define HBITS 17 /* 50% occupancy */
57#define HSIZE (1<<HBITS)
58#define HMASK (HSIZE-1)
59#define HPRIME 9941
60#define BITS 16
61#undef MAXSEG_64K
62#define MAXCODE(n) (1L << (n))
63
64#define htabof(i) htab[i]
65#define codetabof(i) codetab[i]
66#define tab_prefixof(i) codetabof(i)
67#define tab_suffixof(i) ((unsigned char *)(htab))[i]
68#define de_stack ((unsigned char *)&(htab[HSIZE-1]))
69#define clear_htab() memset(htab, -1, HSIZE)
70#define clear_tab_prefixof() memset(codetab, 0, 256);
71 49
50/* machine variants which require cc -Dmachine: pdp11, z8000, DOS */
51#define HBITS 17 /* 50% occupancy */
52#define HSIZE (1<<HBITS)
53#define HMASK (HSIZE-1) /* unused */
54#define HPRIME 9941 /* unused */
55#define BITS 16
56#define BITS_STR "16"
57#undef MAXSEG_64K /* unused */
58#define MAXCODE(n) (1L << (n))
59
60#define htabof(i) htab[i]
61#define codetabof(i) codetab[i]
62#define tab_prefixof(i) codetabof(i)
63#define tab_suffixof(i) ((unsigned char *)(htab))[i]
64#define de_stack ((unsigned char *)&(htab[HSIZE-1]))
65#define clear_tab_prefixof() memset(codetab, 0, 256)
72 66
73/* 67/*
74 * Decompress stdin to stdout. This routine adapts to the codes in the 68 * Decompress stdin to stdout. This routine adapts to the codes in the
75 * file building the "string" table on-the-fly; requiring no table to 69 * file building the "string" table on-the-fly; requiring no table to
76 * be stored in the compressed file. The tables used herein are shared 70 * be stored in the compressed file.
77 * with those of the compress() routine. See the definitions above.
78 */ 71 */
79 72
80USE_DESKTOP(long long) int 73USE_DESKTOP(long long) int
81uncompress(int fd_in, int fd_out) 74uncompress(int fd_in, int fd_out)
82{ 75{
83 USE_DESKTOP(long long total_written = 0;) 76 USE_DESKTOP(long long total_written = 0;)
77 USE_DESKTOP(long long) int retval = -1;
84 unsigned char *stackp; 78 unsigned char *stackp;
85 long code; 79 long code;
86 int finchar; 80 int finchar;
@@ -96,10 +90,10 @@ uncompress(int fd_in, int fd_out)
96 long maxmaxcode; 90 long maxmaxcode;
97 int n_bits; 91 int n_bits;
98 int rsize = 0; 92 int rsize = 0;
99 RESERVE_CONFIG_UBUFFER(inbuf, IBUFSIZ + 64); 93 unsigned char *inbuf; /* were eating insane amounts of stack - */
100 RESERVE_CONFIG_UBUFFER(outbuf, OBUFSIZ + 2048); 94 unsigned char *outbuf; /* bad for some embedded targets */
101 unsigned char htab[HSIZE]; 95 unsigned char *htab;
102 unsigned short codetab[HSIZE]; 96 unsigned short *codetab;
103 97
104 /* Hmm, these were statics - why?! */ 98 /* Hmm, these were statics - why?! */
105 /* user settable max # bits/code */ 99 /* user settable max # bits/code */
@@ -107,8 +101,10 @@ uncompress(int fd_in, int fd_out)
107 /* block compress mode -C compatible with 2.0 */ 101 /* block compress mode -C compatible with 2.0 */
108 int block_mode; /* = BLOCK_MODE; */ 102 int block_mode; /* = BLOCK_MODE; */
109 103
110 memset(inbuf, 0, IBUFSIZ + 64); 104 inbuf = xzalloc(IBUFSIZ + 64);
111 memset(outbuf, 0, OBUFSIZ + 2048); 105 outbuf = xzalloc(OBUFSIZ + 2048);
106 htab = xzalloc(HSIZE); /* wsn't zeroed out before, maybe can xmalloc? */
107 codetab = xzalloc(HSIZE * sizeof(codetab[0]));
112 108
113 insize = 0; 109 insize = 0;
114 110
@@ -116,7 +112,7 @@ uncompress(int fd_in, int fd_out)
116 * to do some cleanup (e.g. delete incomplete unpacked file etc) */ 112 * to do some cleanup (e.g. delete incomplete unpacked file etc) */
117 if (full_read(fd_in, inbuf, 1) != 1) { 113 if (full_read(fd_in, inbuf, 1) != 1) {
118 bb_error_msg("short read"); 114 bb_error_msg("short read");
119 return -1; 115 goto err;
120 } 116 }
121 117
122 maxbits = inbuf[0] & BIT_MASK; 118 maxbits = inbuf[0] & BIT_MASK;
@@ -125,8 +121,8 @@ uncompress(int fd_in, int fd_out)
125 121
126 if (maxbits > BITS) { 122 if (maxbits > BITS) {
127 bb_error_msg("compressed with %d bits, can only handle " 123 bb_error_msg("compressed with %d bits, can only handle "
128 "%d bits", maxbits, BITS); 124 BITS_STR" bits", maxbits);
129 return -1; 125 goto err;
130 } 126 }
131 127
132 n_bits = INIT_BITS; 128 n_bits = INIT_BITS;
@@ -140,7 +136,7 @@ uncompress(int fd_in, int fd_out)
140 free_ent = ((block_mode) ? FIRST : 256); 136 free_ent = ((block_mode) ? FIRST : 256);
141 137
142 /* As above, initialize the first 256 entries in the table. */ 138 /* As above, initialize the first 256 entries in the table. */
143 clear_tab_prefixof(); 139 /*clear_tab_prefixof(); - done by xzalloc */
144 140
145 for (code = 255; code >= 0; --code) { 141 for (code = 255; code >= 0; --code) {
146 tab_suffixof(code) = (unsigned char) code; 142 tab_suffixof(code) = (unsigned char) code;
@@ -232,7 +228,7 @@ uncompress(int fd_in, int fd_out)
232 insize, posbits, p[-1], p[0], p[1], p[2], p[3], 228 insize, posbits, p[-1], p[0], p[1], p[2], p[3],
233 (posbits & 07)); 229 (posbits & 07));
234 bb_error_msg("uncompress: corrupt input"); 230 bb_error_msg("uncompress: corrupt input");
235 return -1; 231 goto err;
236 } 232 }
237 233
238 *--stackp = (unsigned char) finchar; 234 *--stackp = (unsigned char) finchar;
@@ -299,7 +295,11 @@ uncompress(int fd_in, int fd_out)
299 USE_DESKTOP(total_written += outpos;) 295 USE_DESKTOP(total_written += outpos;)
300 } 296 }
301 297
302 RELEASE_CONFIG_BUFFER(inbuf); 298 retval = USE_DESKTOP(total_written) + 0;
303 RELEASE_CONFIG_BUFFER(outbuf); 299 err:
304 return USE_DESKTOP(total_written) + 0; 300 free(inbuf);
301 free(outbuf);
302 free(htab);
303 free(codetab);
304 return retval;
305} 305}