Skip to content

Commit

Permalink
Try to catch null pointers as arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko committed Feb 17, 2022
1 parent 43bfcb6 commit 596d471
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/libirmin/util.ml
Expand Up @@ -21,9 +21,13 @@ module Make (I : Cstubs_inverted.INTERNAL) = struct
try
let () = update_error_msg None in
f ()
with exn ->
let () = update_error_msg @@ Some (Printexc.to_string exn) in
return
with
| Failure msg ->
let () = update_error_msg (Some msg) in
return
| exn ->
let () = update_error_msg @@ Some (Printexc.to_string exn) in
return
[@@inline]

let null t = Ctypes.coerce (ptr void) t null
Expand Down Expand Up @@ -62,7 +66,7 @@ module Make (I : Cstubs_inverted.INTERNAL) = struct

module Root = struct
let to_voidp x = Obj.magic x
let of_voidp x = Obj.magic x
let of_voidp x = if is_null x then failwith "null pointer" else Obj.magic x

let get_repo (type a) (x : Struct.repo ptr) : a repo = Root.get (to_voidp x)
[@@inline]
Expand Down

0 comments on commit 596d471

Please sign in to comment.