From: Junio C Hamano Date: Fri, 23 Jan 2015 18:48:40 GMT Subject: Re: Git compile warnings (under mac/clang) Message-ID: In-Reply-To: <20150123183737.GA32191@peff.net> Jeff King writes: > But of all the options outlined, I think I'd much rather just see an > assert() for something that should never happen, rather than mixing it > into the logic. Surely. > In that vein, one thing that puzzles me is that the current code looks > like: > > if (options->msg_severity && msg_id >= 0 && msg_id < FSCK_MSG_MAX) > severity = options->msg_severity[msg_id]; > else { > severity = msg_id_info[msg_id].severity; > ... > } > > So if the severity override list given by "options" exists, _and_ if we > are in the enum range, then we use that. Otherwise, we dereference the > global list. But wouldn't an out-of-range condition have the exact same > problem dereferencing that global list? > > IOW, should this really be: > > if (msg_id < 0 || msg_id >= FSCK_MSG_MAX) > die("BUG: broken enum"); > > if (options->msg_severity) > severity = options->msg_severity[msg_id]; > else > severity = msg_id_info[msg_id].severity; > > ? And then you can spell that first part as assert(), which I suspect > (but did not test) may shut up clang's warnings. Sounds like a sensible fix to me.