coccinelle: add reallocarray() coccinelle script
Let's systematically make use of reallocarray() whereever we invoke realloc() with a product of two values.
This commit is contained in:
@@ -311,7 +311,7 @@ int unit_file_changes_add(
|
||||
if (!changes)
|
||||
return 0;
|
||||
|
||||
c = realloc(*changes, (*n_changes + 1) * sizeof(UnitFileChange));
|
||||
c = reallocarray(*changes, *n_changes + 1, sizeof(UnitFileChange));
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
*changes = c;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc-util.h"
|
||||
#include "macro.h"
|
||||
#include "uid-range.h"
|
||||
#include "user-util.h"
|
||||
@@ -109,7 +110,7 @@ int uid_range_add(UidRange **p, unsigned *n, uid_t start, uid_t nr) {
|
||||
} else {
|
||||
UidRange *t;
|
||||
|
||||
t = realloc(*p, sizeof(UidRange) * (*n + 1));
|
||||
t = reallocarray(*p, *n + 1, sizeof(UidRange));
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user