[PATCH] lib/util/util.c: move null-check before use
Aurélien Aptel
aaptel at suse.com
Fri Feb 26 10:04:17 UTC 2016
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.
--
Aurélien Aptel / SUSE Labs Samba Team
GPG: 1839 CB5F 9F5B FB9B AA97 8C99 03C8 A49B 521B D5D3
SUSE Linux GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG
Nürnberg)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-lib-util-util.c-move-null-check-before-use.patch
Type: text/x-patch
Size: 1456 bytes
Desc: not available
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160226/94030fc7/0004-lib-util-util.c-move-null-check-before-use.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20160226/94030fc7/attachment.sig>
More information about the samba-technical
mailing list