@@ -112,30 +112,36 @@ int dfltcc_deflate(
112112 int soft_bcc ;
113113 int no_flush ;
114114
115- if (!dfltcc_can_deflate (strm ))
115+ if (!dfltcc_can_deflate (strm )) {
116+ /* Clear history. */
117+ if (flush == Z_FULL_FLUSH )
118+ param -> hl = 0 ;
116119 return 0 ;
120+ }
117121
118122again :
119123 masked_avail_in = 0 ;
120124 soft_bcc = 0 ;
121125 no_flush = flush == Z_NO_FLUSH ;
122126
123- /* Trailing empty block. Switch to software , except when Continuation Flag
124- * is set, which means that DFLTCC has buffered some output in the
125- * parameter block and needs to be called again in order to flush it.
127+ /* No input data. Return , except when Continuation Flag is set, which means
128+ * that DFLTCC has buffered some output in the parameter block and needs to
129+ * be called again in order to flush it.
126130 */
127- if (flush == Z_FINISH && strm -> avail_in == 0 && !param -> cf ) {
128- if ( param -> bcf ) {
129- /* A block is still open, and the hardware does not support closing
130- * blocks without adding data. Thus, close it manually.
131- */
131+ if (strm -> avail_in == 0 && !param -> cf ) {
132+ /* A block is still open, and the hardware does not support closing
133+ * blocks without adding data. Thus, close it manually.
134+ */
135+ if (! no_flush && param -> bcf ) {
132136 send_eobs (strm , param );
133137 param -> bcf = 0 ;
134138 }
135- return 0 ;
136- }
137-
138- if (strm -> avail_in == 0 && !param -> cf ) {
139+ /* Let one of deflate_* functions write a trailing empty block. */
140+ if (flush == Z_FINISH )
141+ return 0 ;
142+ /* Clear history. */
143+ if (flush == Z_FULL_FLUSH )
144+ param -> hl = 0 ;
139145 * result = need_more ;
140146 return 1 ;
141147 }
@@ -189,7 +195,7 @@ int dfltcc_deflate(
189195 param -> cvt = CVT_ADLER32 ;
190196 if (!no_flush )
191197 /* We need to close a block. Always do this in software - when there is
192- * no input data, the hardware will not nohor BCC. */
198+ * no input data, the hardware will not hohor BCC. */
193199 soft_bcc = 1 ;
194200 if (flush == Z_FINISH && !param -> bcf )
195201 /* We are about to open a BFINAL block, set Block Header Final bit
@@ -204,8 +210,8 @@ int dfltcc_deflate(
204210 param -> sbb = (unsigned int )state -> bi_valid ;
205211 if (param -> sbb > 0 )
206212 * strm -> next_out = (Byte )state -> bi_buf ;
207- if ( param -> hl )
208- param -> nt = 0 ; /* Honor history */
213+ /* Honor history and check value */
214+ param -> nt = 0 ;
209215 param -> cv = strm -> adler ;
210216
211217 /* When opening a block, choose a Huffman-Table Type */
0 commit comments