[PATCH] lib/util/util.c: move null-check before use
Jeremy Allison
jra at samba.org
Fri Feb 26 16:37:40 UTC 2016
On Fri, Feb 26, 2016 at 11:04:17AM +0100, Aurélien Aptel wrote:
> Hi Jeremy,
>
> On Thu, 25 Feb 2016 15:12:07 -0800 Jeremy Allison <jra at samba.org> wrote:
> > On Thu, Feb 25, 2016 at 05:06:41PM +0100, Aurélien Aptel wrote:
> > > Hi,
> > >
> > > This patch moves the null pointer check *before* the pointer is
> > > used in the strlen() call.
> > >
> > > - still allocate the `fname` array on the stack
> > > - still compiles under C90 definition/code mixing rules
> > >
> > > Please review&push
> >
> > A bit too 'clever' I'm afraid, although correct.
> >
> > I'd prefer splitting out so len is declared, than
> > initialized after the check for !dir.
>
> If we do this we cannot use a stack-allocated VLA for `fname` because
> we have to declare it after the check, which violates the C90
> definition/code mixing rule (and fails to compile).
>
> I have attached an alternative solution using a regular pointer+alloca()
> if you prefer.
Doh ! No, you're right - your original patch was
just as clever as it needed to be then. Let's avoid
alloca please :-).
Can I get a second Team reviewer for the original patch ?
Cheers,
Jeremy.
More information about the samba-technical
mailing list