Fix calls to malloc() with 2 arguments (#1377)

* Fix calls to malloc() with 2 arguments
This commit is contained in:
Amir Livneh 2019-03-09 19:17:33 -05:00 committed by Sergey Zubkov
parent f67e91d295
commit ba2dbc5edf

View File

@ -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<X*>(malloc(n, X));
p = static_cast<X*>(malloc(n * sizeof(X)));
if (!p) abort(); // abort if memory is exhausted
// ...
}