diff options
Diffstat (limited to 'infcodes.c')
-rw-r--r-- | infcodes.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -29,7 +29,7 @@ struct inflate_codes_state { | |||
29 | LIT, /* o: got literal, waiting for output space */ | 29 | LIT, /* o: got literal, waiting for output space */ |
30 | WASH, /* o: got eob, possibly still output waiting */ | 30 | WASH, /* o: got eob, possibly still output waiting */ |
31 | END, /* x: got eob and all data flushed */ | 31 | END, /* x: got eob and all data flushed */ |
32 | BAD} /* x: got error */ | 32 | BADCODE} /* x: got error */ |
33 | mode; /* current inflate_codes mode */ | 33 | mode; /* current inflate_codes mode */ |
34 | 34 | ||
35 | /* mode dependent information */ | 35 | /* mode dependent information */ |
@@ -70,6 +70,7 @@ z_stream *z; | |||
70 | c->dbits = (Byte)bd; | 70 | c->dbits = (Byte)bd; |
71 | c->ltree = tl; | 71 | c->ltree = tl; |
72 | c->dtree = td; | 72 | c->dtree = td; |
73 | Tracev((stderr, "inflate: codes new\n")); | ||
73 | } | 74 | } |
74 | return c; | 75 | return c; |
75 | } | 76 | } |
@@ -107,7 +108,7 @@ int r; | |||
107 | LOAD | 108 | LOAD |
108 | if (r != Z_OK) | 109 | if (r != Z_OK) |
109 | { | 110 | { |
110 | c->mode = r == Z_STREAM_END ? WASH : BAD; | 111 | c->mode = r == Z_STREAM_END ? WASH : BADCODE; |
111 | break; | 112 | break; |
112 | } | 113 | } |
113 | } | 114 | } |
@@ -124,7 +125,7 @@ int r; | |||
124 | { | 125 | { |
125 | if (e == -128) /* invalid code */ | 126 | if (e == -128) /* invalid code */ |
126 | { | 127 | { |
127 | c->mode = BAD; | 128 | c->mode = BADCODE; |
128 | z->msg = "invalid literal/length code"; | 129 | z->msg = "invalid literal/length code"; |
129 | r = Z_DATA_ERROR; | 130 | r = Z_DATA_ERROR; |
130 | LEAVE | 131 | LEAVE |
@@ -132,6 +133,7 @@ int r; | |||
132 | e = -e; | 133 | e = -e; |
133 | if (e & 64) /* end of block */ | 134 | if (e & 64) /* end of block */ |
134 | { | 135 | { |
136 | Tracevv((stderr, "inflate: end of block\n")); | ||
135 | c->mode = WASH; | 137 | c->mode = WASH; |
136 | break; | 138 | break; |
137 | } | 139 | } |
@@ -142,6 +144,9 @@ int r; | |||
142 | if (e & 16) /* literal */ | 144 | if (e & 16) /* literal */ |
143 | { | 145 | { |
144 | c->sub.lit = t->base; | 146 | c->sub.lit = t->base; |
147 | Tracevv((stderr, t->base >= 0x20 && t->base < 0x7f ? | ||
148 | "inflate: literal '%c'\n" : | ||
149 | "inflate: literal 0x%02x\n", t->base)); | ||
145 | c->mode = LIT; | 150 | c->mode = LIT; |
146 | break; | 151 | break; |
147 | } | 152 | } |
@@ -155,6 +160,7 @@ int r; | |||
155 | DUMPBITS(j) | 160 | DUMPBITS(j) |
156 | c->sub.code.need = c->dbits; | 161 | c->sub.code.need = c->dbits; |
157 | c->sub.code.tree = c->dtree; | 162 | c->sub.code.tree = c->dtree; |
163 | Tracevv((stderr, "inflate: length %u\n", c->len)); | ||
158 | c->mode = DIST; | 164 | c->mode = DIST; |
159 | case DIST: /* i: get distance next */ | 165 | case DIST: /* i: get distance next */ |
160 | j = c->sub.code.need; | 166 | j = c->sub.code.need; |
@@ -165,7 +171,7 @@ int r; | |||
165 | { | 171 | { |
166 | if (e == -128) | 172 | if (e == -128) |
167 | { | 173 | { |
168 | c->mode = BAD; | 174 | c->mode = BADCODE; |
169 | z->msg = "invalid distance code"; | 175 | z->msg = "invalid distance code"; |
170 | r = Z_DATA_ERROR; | 176 | r = Z_DATA_ERROR; |
171 | LEAVE | 177 | LEAVE |
@@ -182,6 +188,7 @@ int r; | |||
182 | NEEDBITS(j) | 188 | NEEDBITS(j) |
183 | c->sub.copy.dist += (uInt)b & inflate_mask[j]; | 189 | c->sub.copy.dist += (uInt)b & inflate_mask[j]; |
184 | DUMPBITS(j) | 190 | DUMPBITS(j) |
191 | Tracevv((stderr, "inflate: distance %u\n", c->sub.copy.dist)); | ||
185 | c->mode = COPY; | 192 | c->mode = COPY; |
186 | case COPY: /* o: copying bytes in window, waiting for space */ | 193 | case COPY: /* o: copying bytes in window, waiting for space */ |
187 | f = (uInt)(q - s->window) < c->sub.copy.dist ? | 194 | f = (uInt)(q - s->window) < c->sub.copy.dist ? |
@@ -210,7 +217,7 @@ int r; | |||
210 | case END: | 217 | case END: |
211 | r = Z_STREAM_END; | 218 | r = Z_STREAM_END; |
212 | LEAVE | 219 | LEAVE |
213 | case BAD: /* x: got error */ | 220 | case BADCODE: /* x: got error */ |
214 | r = Z_DATA_ERROR; | 221 | r = Z_DATA_ERROR; |
215 | LEAVE | 222 | LEAVE |
216 | default: | 223 | default: |
@@ -227,4 +234,5 @@ z_stream *z; | |||
227 | inflate_trees_free(c->dtree, z); | 234 | inflate_trees_free(c->dtree, z); |
228 | inflate_trees_free(c->ltree, z); | 235 | inflate_trees_free(c->ltree, z); |
229 | ZFREE(z, c); | 236 | ZFREE(z, c); |
237 | Tracev((stderr, "inflate: codes free\n")); | ||
230 | } | 238 | } |