Original bug ID: 6575 Reporter: gerd Assigned to:@alainfrisch Status: closed (set by @xavierleroy on 2017-02-16T14:18:27Z) Resolution: fixed Priority: normal Severity: minor Version: 4.02.0 Target version: 4.02.2+dev / +rc1 Category: standard library Related to:#4950 Monitored by:@hcarty
Look at this (ocaml-4.02):
let n = 0 ;;
ignore (Array.init (n-1) (fun _ -> assert false));;
Commit 15898 on 4.02, 15899 on trunk. I've added a check for size < 0 before calling Array.make. Notes:
Array.init used to raise (Invalid_argument "Array.make") in that case, not it raises (Invalid_argument "Array.init"). I don't expect this to break any code and is clearly better.
Checking for the maximum array size is more difficult, since this size depends on whether we are building an array of floats or a regular array (and we don't know before calling the initializer once). Anyway, it is less clear that when the size is too large, the callback should not be called at all.