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:
@@ -721,7 +721,7 @@ char **replace_env_argv(char **argv, char **env) {
|
||||
q = strv_length(m);
|
||||
l = l + q - 1;
|
||||
|
||||
w = realloc(ret, sizeof(char*) * (l+1));
|
||||
w = reallocarray(ret, l + 1, sizeof(char *));
|
||||
if (!w) {
|
||||
ret[k] = NULL;
|
||||
strv_free(ret);
|
||||
|
||||
+1
-1
@@ -173,7 +173,7 @@ int prioq_put(Prioq *q, void *data, unsigned *idx) {
|
||||
struct prioq_item *j;
|
||||
|
||||
n = MAX((q->n_items+1) * 2, 16u);
|
||||
j = realloc(q->items, sizeof(struct prioq_item) * n);
|
||||
j = reallocarray(q->items, n, sizeof(struct prioq_item));
|
||||
if (!j)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
+1
-1
@@ -190,7 +190,7 @@ ssize_t strbuf_add_string(struct strbuf *str, const char *s, size_t len) {
|
||||
node_child->value_len = len;
|
||||
|
||||
/* extend array, add new entry, sort for bisection */
|
||||
child = realloc(node->children, (node->children_count + 1) * sizeof(struct strbuf_child_entry));
|
||||
child = reallocarray(node->children, node->children_count + 1, sizeof(struct strbuf_child_entry));
|
||||
if (!child) {
|
||||
free(node_child);
|
||||
return -ENOMEM;
|
||||
|
||||
+2
-2
@@ -214,7 +214,7 @@ int strv_extend_strv(char ***a, char **b, bool filter_duplicates) {
|
||||
p = strv_length(*a);
|
||||
q = strv_length(b);
|
||||
|
||||
t = realloc(*a, sizeof(char*) * (p + q + 1));
|
||||
t = reallocarray(*a, p + q + 1, sizeof(char *));
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -861,7 +861,7 @@ int strv_extend_n(char ***l, const char *value, size_t n) {
|
||||
|
||||
k = strv_length(*l);
|
||||
|
||||
nl = realloc(*l, sizeof(char*) * (k + n + 1));
|
||||
nl = reallocarray(*l, k + n + 1, sizeof(char *));
|
||||
if (!nl)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user