tree-wide: use reallocarray instead of our home-grown realloc_multiply (#8279)
There isn't much difference, but in general we prefer to use the standard functions. glibc provides reallocarray since version 2.26. I moved explicit_bzero is configure test to the bottom, so that the two stdlib functions are at the bottom.
This commit is contained in:
committed by
Lennart Poettering
parent
f2e3f36950
commit
aa484f3561
@@ -74,12 +74,14 @@ _malloc_ _alloc_(1, 2) static inline void *malloc_multiply(size_t size, size_t
|
||||
return malloc(size * need);
|
||||
}
|
||||
|
||||
_alloc_(2, 3) static inline void *realloc_multiply(void *p, size_t size, size_t need) {
|
||||
#if !HAVE_REALLOCARRAY
|
||||
_alloc_(2, 3) static inline void *reallocarray(void *p, size_t need, size_t size) {
|
||||
if (size_multiply_overflow(size, need))
|
||||
return NULL;
|
||||
|
||||
return realloc(p, size * need);
|
||||
}
|
||||
#endif
|
||||
|
||||
_alloc_(2, 3) static inline void *memdup_multiply(const void *p, size_t size, size_t need) {
|
||||
if (size_multiply_overflow(size, need))
|
||||
|
||||
+3
-3
@@ -407,7 +407,7 @@ int strv_push(char ***l, char *value) {
|
||||
if (m < n)
|
||||
return -ENOMEM;
|
||||
|
||||
c = realloc_multiply(*l, sizeof(char*), m);
|
||||
c = reallocarray(*l, m, sizeof(char*));
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -432,7 +432,7 @@ int strv_push_pair(char ***l, char *a, char *b) {
|
||||
if (m < n)
|
||||
return -ENOMEM;
|
||||
|
||||
c = realloc_multiply(*l, sizeof(char*), m);
|
||||
c = reallocarray(*l, m, sizeof(char*));
|
||||
if (!c)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -546,7 +546,7 @@ int strv_extend_front(char ***l, const char *value) {
|
||||
if (!v)
|
||||
return -ENOMEM;
|
||||
|
||||
c = realloc_multiply(*l, sizeof(char*), m);
|
||||
c = reallocarray(*l, m, sizeof(char*));
|
||||
if (!c) {
|
||||
free(v);
|
||||
return -ENOMEM;
|
||||
|
||||
Reference in New Issue
Block a user