Re: [PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 31, 2011, 17:02 UTC
- Message-ID
- <7vei01zf89.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <1314766126-5060-1-git-send-email-rctay89@gmail.com>
Tay Ray Chuan <rctay89@gmail.com> writes:
Show 6 quoted lines
> Ensure that the xdl_free_classifier() call on xdlclassifier_t cf is safe > even if xdl_init_classifier() isn't called. This may occur in the case > where diff is run with --histogram and a call to, say, xdl_prepare_ctx() > fails. > > Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Thanks. Did you find this by code inspection?
Show 13 quoted lines
> xdiff/xprepare.c | 3 +++ > 1 files changed, 3 insertions(+), 0 deletions(-) > > diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c > index 620fc9a..4323596 100644 > --- a/xdiff/xprepare.c > +++ b/xdiff/xprepare.c > @@ -239,6 +239,9 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, > long enl1, enl2, sample; > xdlclassifier_t cf; > > + cf.rchash = NULL; > + cf.ncha.head = NULL;
Would it be more appropriate to use memcpy(&cf, 0, sizeof(cf)) instead, so that we wouldn't have to worry about a similar breakage when a new field is added to "struct xdlclassifier" later?