#6575: fail early in Array.init when size < 0 to avoid calling the callback in that case. (Cherry-picked from 4.02, rev 15898.)

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15899 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Alain Frisch 2015-03-11 15:13:59 +00:00
parent 4c48d802cb
commit 90a956b47e
2 changed files with 6 additions and 0 deletions

View File

@ -235,6 +235,8 @@ Standard library:
(Jacques Garrigue, report by Mark Shinwell)
- PR#6572: Fatal error with recursive modules
(Jacques Garrigue, report by Quentin Stievenart)
- PR#6575: Array.init evaluates callback although it should not do so
(Alain Frisch, report by Gerd Stolpmann)
- PR#6578: Recursive module containing alias causes Segmentation fault
(Jacques Garrigue)
- PR#6581: Some bugs in generative functors

View File

@ -29,6 +29,10 @@ external make_float: int -> float array = "caml_make_float_vect"
let init l f =
if l = 0 then [||] else
if l < 0 then invalid_arg "Array.init"
(* See #6575. We could also check for maximum array size, but this depends
on whether we create a float array or a regular one... *)
else
let res = create l (f 0) in
for i = 1 to pred l do
unsafe_set res i (f i)