All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()
@ 2011-08-31  4:48 Tay Ray Chuan
  2011-08-31 17:02 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Tay Ray Chuan @ 2011-08-31  4:48 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

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>
---

This should go into 'rc/histogram-diff' in 'next'.

 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;
+
 	/*
 	 * 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()
  2011-08-31  4:48 [PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env() Tay Ray Chuan
@ 2011-08-31 17:02 ` Junio C Hamano
  2011-08-31 17:03   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2011-08-31 17:02 UTC (permalink / raw)
  To: Tay Ray Chuan; +Cc: Git Mailing List

Tay Ray Chuan <rctay89@gmail.com> writes:

> 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?

>  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?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()
  2011-08-31 17:02 ` Junio C Hamano
@ 2011-08-31 17:03   ` Junio C Hamano
  2011-09-02  7:09     ` Tay Ray Chuan
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2011-08-31 17:03 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Tay Ray Chuan, Git Mailing List

Junio C Hamano <gitster@pobox.com> writes:

> Tay Ray Chuan <rctay89@gmail.com> writes:
>
>> 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?
>
>>  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?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()
  2011-08-31 17:03   ` Junio C Hamano
@ 2011-09-02  7:09     ` Tay Ray Chuan
  0 siblings, 0 replies; 4+ messages in thread
From: Tay Ray Chuan @ 2011-09-02  7:09 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano

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 <rctay89@gmail.com>

---

On Thu, Sep 1, 2011 at 1:02 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Tay Ray Chuan <rctay89@gmail.com> writes:
>
>> 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?

If by "code inspection" you meant eye-balling, then yes. :)

On Thu, Sep 1, 2011 at 1:03 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Junio C Hamano <gitster@pobox.com> writes:
> [snip]
>>> @@ -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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-09-02  7:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-31  4:48 [PATCH] xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env() Tay Ray Chuan
2011-08-31 17:02 ` Junio C Hamano
2011-08-31 17:03   ` Junio C Hamano
2011-09-02  7:09     ` Tay Ray Chuan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.