summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-02-26 21:20:00 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:59:05 +0200
commit65c2929bed8254e5ea24bb2d3d5a403a36daf69e (patch)
treefe14db1491ac3f3af433278ea0b93fa54391d12d /src
parentd6ac074bf95f61aeaa9b81db414cc3089fa22f7a (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/basic/alloc-util.h4
-rw-r--r--src/basic/strv.c6
-rw-r--r--src/libelogind/sd-bus/bus-error.c2
3 files changed, 7 insertions, 5 deletions
diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h
index 02dee37d3..ec7808c1f 100644
--- a/src/basic/alloc-util.h
+++ b/src/basic/alloc-util.h
@@ -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))
diff --git a/src/basic/strv.c b/src/basic/strv.c
index 85c55041e..7898e8340 100644
--- a/src/basic/strv.c
+++ b/src/basic/strv.c
@@ -413,7 +413,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;
@@ -438,7 +438,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;
@@ -554,7 +554,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;
diff --git a/src/libelogind/sd-bus/bus-error.c b/src/libelogind/sd-bus/bus-error.c
index c9517499d..3939d0a4e 100644
--- a/src/libelogind/sd-bus/bus-error.c
+++ b/src/libelogind/sd-bus/bus-error.c
@@ -595,7 +595,7 @@ _public_ int sd_bus_error_add_map(const sd_bus_error_map *map) {
if (additional_error_maps[n] == map)
return 0;
- maps = realloc_multiply(additional_error_maps, sizeof(struct sd_bus_error_map*), n + 2);
+ maps = reallocarray(additional_error_maps, n + 2, sizeof(struct sd_bus_error_map*));
if (!maps)
return -ENOMEM;