Introduction
Introduction Statistics Contact Development Disclaimer Help
check a realloc call, use a function wrapper: erealloc - saait - the most borin…
git clone git://git.codemadness.org/saait
Log
Files
Refs
README
LICENSE
---
commit 3d54db5f366efdf4612c9eaa537a22ad11035e45
parent 14e13f2b2eb2a5325046789df95d65cd7afc6e47
Author: Hiltjo Posthuma <[email protected]>
Date: Tue, 29 Oct 2019 17:55:26 +0100
check a realloc call, use a function wrapper: erealloc
Diffstat:
M saait.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
---
diff --git a/saait.c b/saait.c
@@ -73,6 +73,18 @@ ecalloc(size_t nmemb, size_t size)
return p;
}
+void *
+erealloc(void *ptr, size_t size)
+{
+ void *p;
+
+ if (!(p = realloc(ptr, size))) {
+ fprintf(stderr, "realloc: %s\n", strerror(errno));
+ exit(1);
+ }
+ return p;
+}
+
FILE *
efopen(const char *path, const char *mode)
{
@@ -125,10 +137,7 @@ readfile(const char *file)
if (len + READ_BUF_SIZ + 1 > size) {
/* allocate size: common case is small textfiles */
size += READ_BUF_SIZ;
- if (!(buf = realloc(buf, size + 1))) {
- fprintf(stderr, "realloc: %s\n", strerror(errn…
- exit(1);
- }
+ buf = erealloc(buf, size + 1);
}
if (!(n = fread(&buf[len], 1, READ_BUF_SIZ, fp)))
break;
@@ -436,7 +445,7 @@ main(int argc, char *argv[])
fprintf(stderr, "realloc: too many templates: %zu\n", …
exit(1);
}
- templates = realloc(templates, templateslen * sizeof(*template…
+ templates = erealloc(templates, templateslen * sizeof(*templat…
t = &templates[templateslen - 1];
memset(t, 0, sizeof(struct template));
t->name = estrdup(br->d_name);
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.