@@ -213,15 +213,15 @@ namespace lsp
213213 {
214214 // Estimate the length of match
215215 size_t length = sBuffer .lookup (&offset, head, tail-head);
216- const size_t emit = lsp_min (length, 1u );
216+ const size_t emit = lsp_max (length, 1u );
217217
218218 // Calc number of repeats
219219 size_t rep = calc_repeats (&head[emit], tail);
220220 size_t append = emit + lsp_min (rep, REPEAT_BUF_MAX);
221221
222222 // Estimate size of output
223- const size_t est1 = est_uint (sBuffer .size () + *head, 5 , 5 ); // How many bits used to encode buffer replay command
224- const size_t est2 = (length > 0 ) ? est_uint (offset, 5 , 5 ) + est_uint (emit - 1 , 5 , 5 ) : est1 + 1 ; // How many bits used to encode octet command
223+ const size_t est1 = est_uint (sBuffer .size () + *head, 5 , 5 ) * length; // How many bits used to emit octet command
224+ const size_t est2 = (length > 0 ) ? est_uint (offset, 5 , 5 ) + est_uint (emit - 1 , 5 , 5 ) : est1 + 1 ; // How many bits used to encode buffer replay command
225225
226226// IF_TRACE(
227227// if (rep)
@@ -234,7 +234,7 @@ namespace lsp
234234 // Emit Offset
235235 if ((res = emit_uint (offset, 5 , 5 )) != STATUS_OK)
236236 break ;
237- // Emit Length
237+ // Emit Length - 1
238238 if ((res = emit_uint (emit - 1 , 5 , 5 )) != STATUS_OK)
239239 break ;
240240
0 commit comments