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 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.