From: Jonathan Ludlam Date: Thu, 26 Nov 2009 14:39:06 +0000 (+0000) Subject: Fix bug in converting Bigbuffer to a string or other. X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=fc32aedd7d03aa54ee7e1c48dbd99257ffa5dc77;p=xcp%2Fxen-api-libs.git Fix bug in converting Bigbuffer to a string or other. Signed-off-by: Jon Ludlam --- diff --git a/stdext/bigbuffer.ml b/stdext/bigbuffer.ml index 6a6fd4e..0445f56 100644 --- a/stdext/bigbuffer.ml +++ b/stdext/bigbuffer.ml @@ -67,16 +67,17 @@ let to_fct bigbuf f = 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 @@ let to_string bigbuf = ); 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)