Re: [PATCH 31/32] perf, tools: Default to cpu// for events v3

From: Arnaldo Carvalho de Melo
Date: Wed Nov 28 2012 - 16:43:00 EST


Em Wed, Nov 28, 2012 at 08:04:36PM +0100, Andi Kleen escreveu:
> > > +static void str_append(char **s, int *len, const char *a)
> > > +{
> > > + int olen = *s ? strlen(*s) : 0;
> > > + int nlen = olen + strlen(a) + 1;
> > > + if (*len < nlen) {
> > > + *len = *len * 2;
> > > + if (*len < nlen)
> > > + *len = nlen;
> > > + *s = realloc(*s, *len);
> > > + if (!*s)
> > > + exit(ENOMEM);
> >
> > Rather use BUG_ON or event better return -ENOMEM.
>
> Neither makes sense: the callers won't handle it and it's not a bug.
> If you're out of memory in user space the only thing you can do is to
> exit.

Nope, just propagate it back and handle at the callers, the memory
exhaustion may be temporary, just warn the user.

- Arnaldo

> >
> > > + if (olen == 0)
> > > + **s = 0;
> > > + }
> > > + strcat(*s, a);
> > > +}
> >
> > Could this one be moved to util/string.c in some generic form?
>
> Ok.
>
> -Andi
>
> --
> ak@xxxxxxxxxxxxxxx -- Speaking for myself only.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/