simplify malloc - smu - smu - simple markup (Markdown) processor (fork, fixes +… | |
git clone git://git.codemadness.org/smu | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit f3aed972b9371e30d2f31a1ad99950c42734e5f5 | |
parent 0b13fa5e1a5eac764db9bbbdff3199aefe1b43e2 | |
Author: Hiltjo Posthuma <[email protected]> | |
Date: Tue, 11 May 2021 01:51:07 +0200 | |
simplify malloc | |
... realloc(NULL, ...) allocates. | |
Diffstat: | |
M smu.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(… | |
+#define ADDC(b,i) if(i % BUFSIZ == 0) { b = realloc(b, (i + BUFSIZ) * sizeof(… | |
typedef int (*Parser)(const char *, const char *, int); | |
typedef struct { | |
@@ -211,7 +211,7 @@ dolineprefix(const char *begin, const char *end, int newblo… | |
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 newbl… | |
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; | |
} | |