# HG changeset patch # User Jonathan Ludlam # Date 1259246346 0 # Node ID 460ca215d3a5e447683c3fa0368977912586bc9c # Parent 3dad906dec60a34a95bd8dd3963e02218017efa7 Fix bug in converting Bigbuffer to a string or other. Signed-off-by: Jon Ludlam diff -r 3dad906dec60 -r 460ca215d3a5 stdext/bigbuffer.ml --- a/stdext/bigbuffer.ml Fri Nov 20 14:22:16 2009 +0000 +++ b/stdext/bigbuffer.ml Thu Nov 26 14:39:06 2009 +0000 @@ -67,16 +67,17 @@ for i = 0 to array_offset - 1 do match bigbuf.cells.(i) with - | None -> (* ?!?!? *) () + | None -> (* should never happen *) () | Some cell -> f cell done; - (* copy last cell *) - begin match bigbuf.cells.(array_offset) with - | None -> (* ?!?!?! *) () - | Some cell -> f (String.sub cell 0 cell_offset) - end; - () + if(cell_offset > 0) then + (* copy last cell *) + begin match bigbuf.cells.(array_offset) with + | None -> (* Should never happen (any more) *) () + | Some cell -> f (String.sub cell 0 cell_offset) + end + let to_string bigbuf = if bigbuf.index > (Int64.of_int Sys.max_string_length) then @@ -91,5 +92,18 @@ ); dest + +let test max = + let rec inner n = + if n>max then () else begin + let bb = make () in + let s = String.create n in + append_substring bb s 0 n; + assert ((to_string bb)=s); + inner (n+1) + end + in + inner 0 + let to_stream bigbuf outchan = to_fct bigbuf (fun s -> output_string outchan s)