From 7da8331023f3596d478154683fceb82ef94fd085 Mon Sep 17 00:00:00 2001 From: Antoine Drouin Date: Sun, 28 May 2006 16:55:44 +0000 Subject: [PATCH] versatile exception --- sw/lib/ocaml/pprz.ml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sw/lib/ocaml/pprz.ml b/sw/lib/ocaml/pprz.ml index 64ba5688a8..90deed0c24 100644 --- a/sw/lib/ocaml/pprz.ml +++ b/sw/lib/ocaml/pprz.ml @@ -235,7 +235,10 @@ let byte = fun x -> Char.chr (x land 0xff) (** Returns the size of outputed data *) let rec sprint_value = fun buf i _type v -> match _type, v with - Scalar ("int8"|"uint8"), Int x -> buf.[i] <- Char.chr x; sizeof _type + Scalar ("int8"|"uint8"), Int x -> + if x < 0 || x > 0xff then + failwith (sprintf "Value too large to fit in a (u)int8: %d" x); + buf.[i] <- Char.chr x; sizeof _type | Scalar "float", Float f -> sprint_float buf i f; sizeof _type | Scalar "int32", Int32 x -> sprint_int32 buf i x; sizeof _type | Scalar "int16", Int x -> sprint_int16 buf i x; sizeof _type