Commits

camlspotter committed a192d0f

fixed a bug when Sbuffer.substr is given with len=0

Comments (0)

Files changed (1)

+open Spotlib.Spot
+
 (* CR jfuruse: buf and buffer are lousy *)
 type buf = {
   base : Sstring.t; (* underlying stream *)
     create { (buf t) with abs_pos = pos }
 
   let substr t start_abs_pos len =
+    if len <= 0 then "", t else
+    let len_given = len in
     let i = buf t in
     if i.abs_pos.Position.File.byte > start_abs_pos then failwith "Sbuffer.substr: start_abs_pos is over";
     let buffer = Buffer.create len in
     let rec substr stream stream_pos (* abs position of head of buf *) pos len =
       match Sstring.peek stream with
-      | None -> failwith "Sbuffer.substr: end of stream"
+      | None -> failwithf "Sbuffer.substr: end of stream (substr t %d %d)" start_abs_pos len_given
       | Some (string, stream') ->
           (*
           Format.eprintf "substr.substr %d %d %d %s@." stream_pos pos len