Skip to content

Commit

Permalink
Catch [Failure _] in Sscanf functions
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
  • Loading branch information
rgrinberg committed Nov 4, 2019
1 parent 1b09275 commit 5143254
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/stdune/scanf.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module Scanf = Dune_caml.Scanf

let unescaped x =
match Scanf.unescaped x with
let try_ f =
match f () with
| exception End_of_file -> Error ()
| exception Scanf.Scan_failure _ -> Error ()
| exception (Failure _) -> Error ()
| x -> Ok x

let sscanf x fmt f =
match Scanf.sscanf x fmt f with
| exception End_of_file -> Error ()
| exception Scanf.Scan_failure _ -> Error ()
| x -> Ok x
let unescaped x = try_ (fun () -> Scanf.unescaped x)

let sscanf x fmt f = try_ (fun () -> Scanf.sscanf x fmt f)

0 comments on commit 5143254

Please sign in to comment.