smu

Simple markup processor
git clone https://git.sinitax.com/codemadness/smu
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit f3aed972b9371e30d2f31a1ad99950c42734e5f5
parent 0b13fa5e1a5eac764db9bbbdff3199aefe1b43e2
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Tue, 11 May 2021 01:51:07 +0200

simplify malloc

... realloc(NULL, ...) allocates.

Diffstat:
Msmu.c | 11++++-------
1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/smu.c b/smu.c @@ -10,7 +10,7 @@ #include <ctype.h> #define LENGTH(x) sizeof(x)/sizeof(x[0]) -#define ADDC(b,i) if(i % BUFSIZ == 0) { b = realloc(b, (i + BUFSIZ) * sizeof(char)); if(!b) eprint("Malloc failed."); } b[i] +#define ADDC(b,i) if(i % BUFSIZ == 0) { b = realloc(b, (i + BUFSIZ) * sizeof(char)); if(!b) eprint("malloc"); } b[i] typedef int (*Parser)(const char *, const char *, int); typedef struct { @@ -211,7 +211,7 @@ dolineprefix(const char *begin, const char *end, int newblock) { return l - 1; } if(!(buffer = malloc(BUFSIZ))) - eprint("Malloc failed."); + eprint("malloc"); buffer[0] = '\0'; /* Collect lines into buffer while they start with the prefix */ @@ -587,13 +587,10 @@ dounderline(const char *begin, const char *end, int newblock) { void * ereallocz(void *p, size_t size) { void *res; - if(p) - res = realloc(p , size); - else - res = calloc(1, size); + res = realloc(p, size); if(!res) - eprint("fatal: could not malloc() %u bytes\n", size); + eprint("realloc: %zu bytes\n", size); return res; }