Re: [bug?] checkout -m doesn't work without a base version

Subsystems: the rest

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

Re: [bug?] checkout -m doesn't work without a base version

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:39

Andreas Schwab [off-list ref] writes:
Junio C Hamano [off-list ref] writes:
quoted
The variable "mode" is assigned to when we see an stage #2 entry in the
loop, and we should have updated threeway[1] immediately before doing so.
If threeway[1] is not updated, we would have already returned before using
the variable in make_cache_entry().
How can you be sure that ce_stage(ce) ever returns 2?
You cannot and and there are cases where you exit the loop without finding
a stage #2 entry. But in that case threeway[1] stays 0{40} and control is
returned to the caller without ever getting to the place where the
variable is used.

You could do the usual "unnecessary initialization" trick, though.

 builtin/checkout.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 31aa248..064e7a1 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -152,7 +152,7 @@ static int checkout_merged(int pos, struct checkout *state)
 	unsigned char sha1[20];
 	mmbuffer_t result_buf;
 	unsigned char threeway[3][20];
-	unsigned mode;
+	unsigned mode = 0;
 
 	memset(threeway, 0, sizeof(threeway));
 	while (pos < active_nr) {

Re: [bug?] checkout -m doesn't work without a base version

From: Ramsay Jones <hidden>
Date: 2016-06-15 22:52:39

Junio C Hamano wrote:
You could do the usual "unnecessary initialization" trick, though.
Yes, I wrote exactly this patch some days ago (when it first appeared
in pu), but haven't found the time to send it ... :-D

ATB,
Ramsay Jones
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help