Re: [PATCH 2/2] perf: use XSI-complaint version of strerror_r()instead of GNU-specific

From: Kirill A. Shutemov
Date: Mon Jul 23 2012 - 17:06:00 EST


On Mon, Jul 23, 2012 at 04:48:22PM -0400, Ulrich Drepper wrote:
> On Mon, Jul 23, 2012 at 4:31 PM, Kirill A. Shutemov
> <kirill@xxxxxxxxxxxxx> wrote:
> > + const char *err = strerror_r(errnum, buf, buflen);
> > +
> > + if (err != buf && buflen > 0) {
> > + size_t len = strlen(err);
> > + char *c = mempcpy(buf, err, min(buflen - 1, len));
> > + *c = '\0';
> > + }
>
> No need to check for err == NULL.

There's no such check.

> buflen == 0 is a possibility given
> the interface but I'd say this is an error and should be tested for at
> the beginning of the function and the call should fail or even abort
> the program.