[OpenWrt-Devel] [PATCH 2/5] utils: refine calloc_a a bit.

Yousong Zhou yszhou4tech at gmail.com
Fri Jun 5 11:03:26 EDT 2015


On Jun 5, 2015 3:14 PM, "Felix Fietkau" <nbd at openwrt.org> wrote:
>
> On 2015-06-04 15:41, Yousong Zhou wrote:
> >  - Return early on calloc() failure.
> >  - Correct comment text for __calloc_a().
> >
> > Signed-off-by: Yousong Zhou <yszhou4tech at gmail.com>
> > ---
> >  utils.c |    4 ++++
> >  utils.h |    6 +++---
> >  2 files changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/utils.c b/utils.c
> > index 8fd19f4..627b0f6 100644
> > --- a/utils.c
> > +++ b/utils.c
> > @@ -43,6 +43,10 @@ void *__calloc_a(size_t len, ...)
> >       va_end(ap1);
> >
> >       ptr = calloc(1, alloc_len);
> > +     if (!ptr) {
> > +             va_end(ap);
> > +             return NULL;
> > +     }
> What's the point? The return value without this check will be NULL
> anyway, and optimizing a rare error case does not seem useful to me.
>

rare case indeed, also a trivial change.  null check is for correctness.
it also seems to me assigning invalid pointer values to output arguments is
not right.  well, my 2 cents :)

                yousong

> - Felix
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20150605/9030da48/attachment.htm>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list