Re: [PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:51:57

Junio C Hamano [off-list ref] writes:
Tay Ray Chuan [off-list ref] writes:
quoted
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 <redacted>
Thanks. Did you find this by code inspection?
quoted
 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
Oops, I meant memset(), obviously.
that we wouldn't have to worry about a similar breakage when a new field
is added to "struct xdlclassifier" later?

[PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()

From: Tay Ray Chuan <hidden>
Date: 2016-06-15 22:51:58

Ensure that the xdl_free_classifier() call on xdlclassifier_t cf is safe
even if xdl_init_classifier() isn't called, which is the case when diff
is run with --histogram.

Signed-off-by: Tay Ray Chuan <redacted>

---

On Thu, Sep 1, 2011 at 1:02 AM, Junio C Hamano [off-list ref] wrote:
Tay Ray Chuan [off-list ref] writes:
quoted
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 <redacted>
Thanks. Did you find this by code inspection?
If by "code inspection" you meant eye-balling, then yes. :)

On Thu, Sep 1, 2011 at 1:03 AM, Junio C Hamano [off-list ref] wrote:
Junio C Hamano [off-list ref] writes:
[snip]
quoted
quoted
@@ -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
Oops, I meant memset(), obviously.
Right, thanks.
---
 xdiff/xprepare.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/xdiff/xprepare.c b/xdiff/xprepare.c
index 620fc9a..5b676b7 100644
--- a/xdiff/xprepare.c
+++ b/xdiff/xprepare.c
@@ -239,6 +239,8 @@ int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
 	long enl1, enl2, sample;
 	xdlclassifier_t cf;
 
+	memset(&cf, 0, sizeof(cf));
+
 	/*
 	 * For histogram diff, we can afford a smaller sample size and
 	 * thus a poorer estimate of the number of lines, as the hash
-- 
1.7.6.1.706.gaa5cf
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help