From 1e867c804ed11200c8ed1a55a71f416977249363 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Tue, 21 Feb 2017 14:01:51 +0100 Subject: Added check for large arrays. The check tests whether the size calculation of an array overflows or the array covers half of the available address space and reports an error in this case. Bug 21034 --- cparser/Cutil.ml | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'cparser/Cutil.ml') diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml index 124560e5..586b4a92 100644 --- a/cparser/Cutil.ml +++ b/cparser/Cutil.ml @@ -642,6 +642,17 @@ let int_representable v nbits sgn = else 0L <= v && v < Int64.shift_left 1L nbits +let valid_array_size env ty v = + match sizeof env ty with + | None -> true (* Incomplete type should be caught later *) + | Some sz -> + let sz = Int64.of_int sz in + let ptr_bits = !Machine.config.sizeof_ptr * 8 - 1 in + if sz = 0L || v <= (Int64.div Int64.max_int sz) then + int_representable (Int64.mul sz v) ptr_bits true + else + false + (* Type of a function definition *) let fundef_typ fd = -- cgit