From: Zbigniew Jędrzejewski-Szmek Date: Thu, 11 Apr 2013 22:58:45 +0000 (-0400) Subject: util: add wrapper for realloc to avoid specyfing type X-Git-Tag: v202~117 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=2244a6fbe6012924e74c7f2197512a55e9238b05 util: add wrapper for realloc to avoid specyfing type --- diff --git a/src/libsystemd-bus/bus-match.c b/src/libsystemd-bus/bus-match.c index fed25c1a2..37e7cc71f 100644 --- a/src/libsystemd-bus/bus-match.c +++ b/src/libsystemd-bus/bus-match.c @@ -725,7 +725,7 @@ static int parse_match( } } - if (!greedy_realloc((void**) &value, &value_allocated, j + 2)) { + if (!GREEDY_REALLOC(value, value_allocated, j + 2)) { r = -ENOMEM; goto fail; } @@ -744,8 +744,7 @@ static int parse_match( } else u = 0; - if (!greedy_realloc((void**) &components, &components_allocated, - (n_components + 1) * sizeof(struct match_component))) { + if (!GREEDY_REALLOC(components, components_allocated, n_components + 1)) { r = -ENOMEM; goto fail; } diff --git a/src/shared/util.h b/src/shared/util.h index a8e962ea5..99ec0a39b 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -618,6 +618,8 @@ char *strextend(char **x, ...); char *strrep(const char *s, unsigned n); void* greedy_realloc(void **p, size_t *allocated, size_t need); +#define GREEDY_REALLOC(array, allocated, need) \ + greedy_realloc((void**) &(array), &(allocated), (sizeof *array) * (need)) static inline void _reset_errno_(int *saved_errno) { errno = *saved_errno;