diff --git a/infer/src/bufferoverrun/bufferOverrunModels.ml b/infer/src/bufferoverrun/bufferOverrunModels.ml index e5bc7ce09..ea484b510 100644 --- a/infer/src/bufferoverrun/bufferOverrunModels.ml +++ b/infer/src/bufferoverrun/bufferOverrunModels.ml @@ -186,7 +186,10 @@ let placement_new size_exp (src_exp1, t1) src_arg2_opt = | Some (src_exp2, t2) when Typ.is_pointer_to_void t2 -> src_exp2 | _ -> - L.(die InternalError) "Unexpected types of arguments for __placement_new" + (* TODO: Raise an exception when given unexpected arguments. Before that, we need + to fix the frontend to parse user defined `new` correctly. *) + L.(debug BufferOverrun Verbose) "Unexpected types of arguments for __placement_new" ; + src_exp1 in let v = Sem.eval src_exp mem in Dom.Mem.add_stack (Loc.of_id id) v mem diff --git a/infer/tests/codetoanalyze/cpp/bufferoverrun/class.cpp b/infer/tests/codetoanalyze/cpp/bufferoverrun/class.cpp index 08eb7576c..c880e1c07 100644 --- a/infer/tests/codetoanalyze/cpp/bufferoverrun/class.cpp +++ b/infer/tests/codetoanalyze/cpp/bufferoverrun/class.cpp @@ -131,6 +131,20 @@ void placement_new_overload4_Good() { x->a[0] = 0; } +struct Allocator { + void* allocate(std::size_t size) { return malloc(size); } +}; + +void* operator new(std::size_t size, Allocator& allocator) { + return allocator.allocate(size); +} + +void user_defined_new_Bad_FN() { + Allocator allocator; + my_class2* x = new (allocator) my_class2(); + x->a[10] = 0; +} + class my_class4 { public: int a[3];