Skip to content

Commit

Permalink
Rng.generate_into: check that off and n are positive
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Jan 7, 2025
1 parent 520732b commit fafabab
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rng/rng.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ let get = function Some g -> g | None -> default_generator ()
let generate_into ?(g = default_generator ()) b ?(off = 0) n =
let Generator (g, _, m) = g in
let module M = (val m) in
if off < 0 || n < 0 then
invalid_arg ("negative offset " ^ string_of_int off ^ " or length " ^
string_of_int n);
if Bytes.length b - off < n then
invalid_arg "buffer too short";
M.generate_into ~g b ~off n
Expand Down

0 comments on commit fafabab

Please sign in to comment.