nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit c556526488eee88c58b4cb91a9bb31a3f97170ee
parent 63d64d7cf894b83b43ce7c9ef9aa0b4cc0129723
Author: Rolf Eike Beer <eike@sf-mail.de>
Date:   Sat, 13 Jun 2020 15:05:34 +0200

get rid of alloc_re()

It was called from only 2 places and had a slightly unusual interface. Since
those lines have been changed already they would collide in a diff anyway, so
change them to use realloc() directly, which is a known interface for anyone
that wants to change this lines again.

The conversion rules are simply: pass x instead of &x as first argument, and
simply remove the second one. Do the usual realloc() return value checking and
assignment at the callsite.

This has the implicit bonus that another allocation function now uses size_t.

Diffstat:
Malloc.h | 8--------
Menv.c | 5++++-
Mgen_allocdefs.h | 5++++-
3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/alloc.h b/alloc.h @@ -5,13 +5,5 @@ #define alloc(x) malloc(x) #define alloc_free(x) free(x) -static inline int alloc_re(void **x, unsigned int m, unsigned int n) -{ - void *y = realloc(*x, n); - (void)m; - if (y != NULL) - *x = y; - return !!y; -} #endif diff --git a/env.c b/env.c @@ -54,9 +54,12 @@ static int env_add(s) char *s; if (t) env_unsetlen(s,t - s); if (en == ea) { + char **nenv; ea += 30; - if (!alloc_re((void**)&environ,(en + 1) * sizeof(char *),(ea + 1) * sizeof(char *))) + nenv = realloc(environ, (ea + 1) * sizeof(char *)); + if (nenv == NULL) { ea = en; return 0; } + environ = nenv; } environ[en++] = s; environ[en] = 0; diff --git a/gen_allocdefs.h b/gen_allocdefs.h @@ -12,6 +12,7 @@ static int ta_rplus ## _internal (ta *x, unsigned int n, unsigned int pluslen) \ errno = error_nomem; \ if (x->field) { \ unsigned int nnum; \ + type *nfield; \ if (__builtin_add_overflow(n, pluslen, &n)) \ return 0; \ if (n <= x->a) \ @@ -20,8 +21,10 @@ static int ta_rplus ## _internal (ta *x, unsigned int n, unsigned int pluslen) \ return 0; \ if (__builtin_mul_overflow(nnum, sizeof(type), &nlen)) \ return 0; \ - if (!alloc_re((void**)&x->field,x->a * sizeof(type),nlen)) \ + nfield = realloc(x->field, nlen); \ + if (nfield == NULL) \ return 0; \ + x->field = nfield; \ x->a = nnum; \ return 1; } \ x->len = 0; \