]> xenbits.xensource.com Git - xcp/xen-api-libs.git/commitdiff
Fix bug in converting Bigbuffer to a string or other.
authorJonathan Ludlam <Jonathan.Ludlam@eu.citrix.com>
Thu, 26 Nov 2009 14:39:06 +0000 (14:39 +0000)
committerJonathan Ludlam <Jonathan.Ludlam@eu.citrix.com>
Thu, 26 Nov 2009 14:39:06 +0000 (14:39 +0000)
Signed-off-by: Jon Ludlam <Jonathan.Ludlam@eu.citrix.com>
stdext/bigbuffer.ml

index 6a6fd4ef2e71669d3ee02e28da6990860ccaa2f7..0445f564f257ebcc97a87b87032e575feda0ac3a 100644 (file)
@@ -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)