more paranoid decoder, with bugfix

This commit is contained in:
Simon Cruanes 2013-08-29 23:23:41 +02:00
parent 197f7eb786
commit b0f70fbd4e

View file

@ -290,17 +290,17 @@ let parse dec s i len =
(* add the input to [dec] *) (* add the input to [dec] *)
if dec.len = 0 if dec.len = 0
then begin then begin
dec.buf <- s; dec.buf <- String.copy s;
dec.i <- i; dec.i <- i;
dec.len <- len; dec.len <- len;
end else begin end else begin
(* use a buffer to merge the stored input and the new input *) (* use a buffer to merge the stored input and the new input *)
let b = Buffer.create (dec.len + len) in let buf' = String.create (dec.len + len - dec.i) in
Buffer.add_substring b dec.buf dec.i dec.len; String.blit dec.buf dec.i buf' 0 dec.len;
Buffer.add_substring b s i len; String.blit s i buf' dec.len len;
dec.buf <- Buffer.contents b; dec.buf <- buf';
dec.i <- 0; dec.i <- 0;
dec.len <- dec.len + len; dec.len <- dec.len + len - dec.i;
end; end;
(* state machine *) (* state machine *)
parse_rec dec parse_rec dec