On Fri, Aug 12, 2016 at 03:06:06PM +0200, Markus Teich wrote:
> Heyho,
>
> Hiltjo Posthuma wrote:
> > Here is a patch that improve the error messages a bit more and a patch that
> > checks a memory allocation case.
>
> Thanks, I clarified the split error messages in the first one a bit.
>
> > Subject: [PATCH 2/2] check memory allocation for calloc, die on failure
> >
> > …
> >
> > - s->img = calloc(1, sizeof(Image));
> > + s->img = ecalloc(1, sizeof(Image));
>
> ecalloc does not call die() on failure. It just prints the errno string without
> a prefix and then returns NULL. Should we change that to call die() instead? It
> would simplify some cases in sent at least, where we currently call
> malloc/calloc and check the return code. Is there a case in the other projects
> where we don't want to die() on allocation failures? If there are just a few,
> they might switch back from ecalloc to calloc. Another option might be to
> introduce wecalloc like weprintf in sbase.
>
> --Markus
>
Ah, I assumed it did because the other tools (sbase, ubase, etc) exit on
ecalloc/emalloc. Anyway I think we should change that in sent, below is a patch
which changes this:
diff --git a/util.c b/util.c
index b0612af..fe044fc 100644
--- a/util.c
+++ b/util.c
_AT_@ -12,7 +12,7 @@ ecalloc(size_t nmemb, size_t size)
void *p;
if (!(p = calloc(nmemb, size)))
- perror(NULL);
+ die("calloc:");
return p;
}
--
Kind regards,
Hiltjo
Received on Fri Aug 12 2016 - 17:43:18 CEST