git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Tay Ray Chuan <rctay89@gmail.com>
Date
Sep 2, 2011, 07:09 UTC
Message-ID
<1314947363-4596-1-git-send-email-rctay89@gmail.com>
In-Reply-To
<7vaaapzf6f.fsf@alter.siamese.dyndns.org>

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:
Show 10 quoted lines
> 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:
Show 12 quoted lines
> 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
Previous: Junio C Hamano
Message 4 of 4 in “xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()”
  1. xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()Tay Ray Chuan, Aug 31, 2011
  2. Junio C HamanoAug 31, 2011
  3. Junio C HamanoAug 31, 2011
  4. xdiff/xprepare: initialise xdlclassifier_t cf in xdl_prepare_env()Tay Ray Chuan, Sep 2, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.