From: Ævar Arnfjörð Bjarmason Date: Tue, 18 Oct 2022 09:23:10 GMT Subject: Re: [RFC PATCH 2/2] notes.c: fixed tip when target and append note are both empty Message-ID: <221018.864jw1jxfx.gmgdl@evledraar.gmail.com> In-Reply-To: <20221018031144.73730-1-tenglong.tl@alibaba-inc.com> On Tue, Oct 18 2022, Teng Long wrote: > "Ævar Arnfjörð Bjarmason" writes: > >> Hrm, interesting that (at least my) gcc doesn't catch if we don't >> NULL-initialize this, but -fanalyzer does (usually it's not needed for >> such trivial cases0. Anyawy... > > On my local env the warnings shows , show I change the line (initialize with > NULL to "logmsg"). > > But it seems like different as the last time I built... However now "suggest > braces around initialization of subobject" appears, is it normal or we should > repair this? > > builtin/merge-file.c:29:23: warning: suggest braces around initialization of subobject [-Wmissing-braces] > mmfile_t mmfs[3] = { 0 }; > ^ > {} > builtin/merge-file.c:31:20: warning: suggest braces around initialization of subobject [-Wmissing-braces] > xmparam_t xmp = { 0 }; > ^ > {} The fix for this is in "next": 54795d37d9e (config.mak.dev: disable suggest braces error on old clang versions, 2022-10-10) > 2 warnings generated. > builtin/notes.c:641:13: warning: variable 'logmsg' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] > } else if (!cp.buf.len) { > ^~~~~~~~~~~ > builtin/notes.c:653:7: note: uninitialized use occurs here > free(logmsg); > ^~~~~~ > builtin/notes.c:641:9: note: remove the 'if' if its condition is always false > } else if (!cp.buf.len) { > ^~~~~~~~~~~~~~~~~~ > builtin/notes.c:570:14: note: initialize the variable 'logmsg' to silence this warning > char *logmsg; > ^ > = NULL > 1 warning generated. Yes, we should initialize it to NULL, so this is the expected warning. Clang spots it.