Re: [bug?] checkout -m doesn't work without a base version
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:52:38
Michael Schubert [off-list ref] writes:
quoted
... + memset(threeway, 0, sizeof(threeway)); + while (pos < active_nr) { + int stage; + stage = ce_stage(ce); + if (!stage || strcmp(path, ce->name)) + break; + hashcpy(threeway[stage - 1], ce->sha1); + if (stage == 2) + mode = create_ce_mode(ce->ce_mode); + pos++; + ce = active_cache[pos]; + } + if (is_null_sha1(threeway[1]) || is_null_sha1(threeway[2])) + return error(_("path '%s' does not have necessary versions"), path); ... + ce = make_cache_entry(mode, sha1, path, 2, 0); if (!ce) die(_("make_cache_entry failed for path '%s'"), path); status = checkout_entry(ce, state, NULL);gcc 4.6.2: builtin/checkout.c: In function ‘cmd_checkout’: builtin/checkout.c:210:5: warning: ‘mode’ may be used uninitialized in this function [-Wuninitialized] builtin/checkout.c:160:11: note: ‘mode’ was declared here
Isn't this just your gcc being overly cautious (aka "silly")? 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().