Skip to content

Commit fafabab

Browse files
committed
Rng.generate_into: check that off and n are positive
1 parent 520732b commit fafabab

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

rng/rng.ml

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ let get = function Some g -> g | None -> default_generator ()
7373
let generate_into ?(g = default_generator ()) b ?(off = 0) n =
7474
let Generator (g, _, m) = g in
7575
let module M = (val m) in
76+
if off < 0 || n < 0 then
77+
invalid_arg ("negative offset " ^ string_of_int off ^ " or length " ^
78+
string_of_int n);
7679
if Bytes.length b - off < n then
7780
invalid_arg "buffer too short";
7881
M.generate_into ~g b ~off n

0 commit comments

Comments
 (0)