* [PATCH] Fix an unitialized pointer in merge-recursive.c
@ 2007-08-16 8:00 Marco Costalba
2007-08-16 8:08 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Marco Costalba @ 2007-08-16 8:00 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
Indeed &mrtree is passed to merge_trees() that not always
seems to set the value, so on some paths mrtree could
return uninitialized.
Spotted by a gcc 4.2.1 warning
Signed-off-by: Marco Costalba <mcostalba@gmail.com>
---
merge-recursive.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 16f6a0f..934b0d6 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -1610,7 +1610,7 @@ static int merge(struct commit
{
struct commit_list *iter;
struct commit *merged_common_ancestors;
- struct tree *mrtree;
+ struct tree *mrtree = NULL;
int clean;
if (show(4)) {
--
1.5.3.rc4.67.gf9286
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix an unitialized pointer in merge-recursive.c
2007-08-16 8:00 [PATCH] Fix an unitialized pointer in merge-recursive.c Marco Costalba
@ 2007-08-16 8:08 ` Junio C Hamano
2007-08-16 8:11 ` Marco Costalba
0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2007-08-16 8:08 UTC (permalink / raw)
To: Marco Costalba; +Cc: Git Mailing List
"Marco Costalba" <mcostalba@gmail.com> writes:
> Indeed &mrtree is passed to merge_trees() that not always
> seems to set the value, so on some paths mrtree could
> return uninitialized.
>
> Spotted by a gcc 4.2.1 warning
Are you sure that gcc is correctly seeing the codeflow?
In merge(), mrtree is used only under index_only, and
merge_trees() always sets *result under index_only.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix an unitialized pointer in merge-recursive.c
2007-08-16 8:08 ` Junio C Hamano
@ 2007-08-16 8:11 ` Marco Costalba
2007-08-16 8:23 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Marco Costalba @ 2007-08-16 8:11 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
On 8/16/07, Junio C Hamano <gitster@pobox.com> wrote:
> "Marco Costalba" <mcostalba@gmail.com> writes:
>
> > Indeed &mrtree is passed to merge_trees() that not always
> > seems to set the value, so on some paths mrtree could
> > return uninitialized.
> >
> > Spotted by a gcc 4.2.1 warning
>
> Are you sure that gcc is correctly seeing the codeflow?
>
> In merge(), mrtree is used only under index_only, and
> merge_trees() always sets *result under index_only.
>
Ok ;-)
Now two options:
- discard the patch
- change the title in 'silence a gcc bougus warning'
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix an unitialized pointer in merge-recursive.c
2007-08-16 8:11 ` Marco Costalba
@ 2007-08-16 8:23 ` Junio C Hamano
2007-08-16 8:30 ` Junio C Hamano
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Junio C Hamano @ 2007-08-16 8:23 UTC (permalink / raw)
To: Marco Costalba; +Cc: Junio C Hamano, Git Mailing List
"Marco Costalba" <mcostalba@gmail.com> writes:
> On 8/16/07, Junio C Hamano <gitster@pobox.com> wrote:
>> "Marco Costalba" <mcostalba@gmail.com> writes:
>>
>> > Indeed &mrtree is passed to merge_trees() that not always
>> > seems to set the value, so on some paths mrtree could
>> > return uninitialized.
>> >
>> > Spotted by a gcc 4.2.1 warning
>>
>> Are you sure that gcc is correctly seeing the codeflow?
>>
>> In merge(), mrtree is used only under index_only, and
>> merge_trees() always sets *result under index_only.
>>
>
> Ok ;-)
>
> Now two options:
>
> - discard the patch
>
> - change the title in 'silence a gcc bougus warning'
Third option. Change the assignment from "mrtree = NULL" to
"mrtree = mtree". It is a standard idiom to work around stupid
gcc warnings.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix an unitialized pointer in merge-recursive.c
2007-08-16 8:23 ` Junio C Hamano
@ 2007-08-16 8:30 ` Junio C Hamano
2007-08-16 9:07 ` David Kastrup
2007-08-16 13:16 ` Florian Weimer
2 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2007-08-16 8:30 UTC (permalink / raw)
To: Marco Costalba; +Cc: Junio C Hamano, Git Mailing List
Junio C Hamano <gitster@pobox.com> writes:
> Third option. Change the assignment from "mrtree = NULL" to
> "mrtree = mtree". It is a standard idiom to work around stupid
> gcc warnings.
Oops; it might be obvious but that's "mrtree = mrtree".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix an unitialized pointer in merge-recursive.c
2007-08-16 8:23 ` Junio C Hamano
2007-08-16 8:30 ` Junio C Hamano
@ 2007-08-16 9:07 ` David Kastrup
2007-08-16 13:16 ` Florian Weimer
2 siblings, 0 replies; 7+ messages in thread
From: David Kastrup @ 2007-08-16 9:07 UTC (permalink / raw)
To: git
Junio C Hamano <gitster@pobox.com> writes:
> "Marco Costalba" <mcostalba@gmail.com> writes:
>
>> On 8/16/07, Junio C Hamano <gitster@pobox.com> wrote:
>>> "Marco Costalba" <mcostalba@gmail.com> writes:
>>>
>>> > Indeed &mrtree is passed to merge_trees() that not always
>>> > seems to set the value, so on some paths mrtree could
>>> > return uninitialized.
>>> >
>>> > Spotted by a gcc 4.2.1 warning
>>>
>>> Are you sure that gcc is correctly seeing the codeflow?
>>>
>>> In merge(), mrtree is used only under index_only, and
>>> merge_trees() always sets *result under index_only.
>>
>> Ok ;-)
>>
>> Now two options:
>>
>> - discard the patch
>>
>> - change the title in 'silence a gcc bougus warning'
>
> Third option. Change the assignment from "mrtree = NULL" to
> "mrtree = mtree". It is a standard idiom to work around stupid
> gcc warnings.
I think it is more efficient to write mrtree = NULL: For the computer,
it makes a minuscule difference, and it can save programmers a bit of
confusion and worrying times. Time that may be better spent improving
things elsewhere.
I don't think that we have a contest running for least redundancy in
code layout, have we? Why then require the programmer to do a
complete call trace analysis before he can feel comfortable about the
code? And what if callers change at some point of time?
--
David Kastrup
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] Fix an unitialized pointer in merge-recursive.c
2007-08-16 8:23 ` Junio C Hamano
2007-08-16 8:30 ` Junio C Hamano
2007-08-16 9:07 ` David Kastrup
@ 2007-08-16 13:16 ` Florian Weimer
2 siblings, 0 replies; 7+ messages in thread
From: Florian Weimer @ 2007-08-16 13:16 UTC (permalink / raw)
To: git
* Junio C. Hamano:
> Third option. Change the assignment from "mrtree = NULL" to
> "mrtree = mtree". It is a standard idiom to work around stupid
> gcc warnings.
Is it? It's also undefined according to the C standard. In other
words, the compiler may assume that this particular declaration is
never reached.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-08-16 13:16 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-16 8:00 [PATCH] Fix an unitialized pointer in merge-recursive.c Marco Costalba
2007-08-16 8:08 ` Junio C Hamano
2007-08-16 8:11 ` Marco Costalba
2007-08-16 8:23 ` Junio C Hamano
2007-08-16 8:30 ` Junio C Hamano
2007-08-16 9:07 ` David Kastrup
2007-08-16 13:16 ` Florian Weimer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).