From ba2dbc5edf1e0257ed7397a1c803f3f5540461ec Mon Sep 17 00:00:00 2001 From: Amir Livneh Date: Sat, 9 Mar 2019 19:17:33 -0500 Subject: [PATCH] Fix calls to malloc() with 2 arguments (#1377) * Fix calls to malloc() with 2 arguments --- CppCoreGuidelines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index c11ce96..62a3835 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -15787,7 +15787,7 @@ Better: void f(int n) { - void* p = malloc(1, n); + void* p = malloc(n); auto _ = finally([p] { free(p); }); // ... } @@ -15891,7 +15891,7 @@ In such cases, "crashing" is simply leaving error handling to the next level of void f(int n) { // ... - p = static_cast(malloc(n, X)); + p = static_cast(malloc(n * sizeof(X))); if (!p) abort(); // abort if memory is exhausted // ... }