chiark / gitweb /
util: add wrapper for realloc to avoid specyfing type
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 11 Apr 2013 22:58:45 +0000 (18:58 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 12 Apr 2013 23:26:12 +0000 (19:26 -0400)
src/libsystemd-bus/bus-match.c
src/shared/util.h

index fed25c1a2aeda0576e0a52818cf0a66ac0833746..37e7cc71f38c2a0d6a7db919175336fe914ba929 100644 (file)
@@ -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;
                         }
                                 r = -ENOMEM;
                                 goto fail;
                         }
@@ -744,8 +744,7 @@ static int parse_match(
                 } else
                         u = 0;
 
                 } 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;
                 }
                         r = -ENOMEM;
                         goto fail;
                 }
index a8e962ea50af16365c2e9295defd275928c447da..99ec0a39bdc4ee1212d4f6aec5ab974c3468d4a9 100644 (file)
@@ -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);
 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;
 
 static inline void _reset_errno_(int *saved_errno) {
         errno = *saved_errno;