git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Git compile warnings (under mac/clang)

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jan 23, 2015, 18:46 UTC
Message-ID
<321a67762d18795b743b242618950849@www.dscho.org>
In-Reply-To
<20150123183737.GA32191@peff.net>
Hi Peff,
On 2015-01-23 19:37, Jeff King wrote:
Show 29 quoted lines
> On Fri, Jan 23, 2015 at 10:07:18AM -0800, Junio C Hamano wrote:
> 
> [...] 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.
To be quite honest, I assumed that Git's source code was assert()-free. But I was wrong! So I'll go with that solution; it is by far the nicest one IMHO.

Thanks! Dscho

Previous: Jeff KingNext: Jeff King
Message 12 of 15 in “Git compile warnings (under mac/clang)”
  1. Michael BlumeJan 22, 2015
  2. Stefan BellerJan 22, 2015
  3. Peter WuJan 22, 2015
  4. Johannes SchindelinJan 22, 2015
  5. Jeff KingJan 22, 2015
  6. Johannes SchindelinJan 23, 2015
  7. Jeff KingJan 23, 2015
  8. Johannes SchindelinJan 23, 2015
  9. Jeff KingJan 23, 2015
  10. Junio C HamanoJan 23, 2015
  11. Jeff KingJan 23, 2015
  12. Johannes SchindelinJan 23, 2015
  13. Jeff KingJan 23, 2015
  14. Johannes SchindelinJan 23, 2015
  15. Junio C HamanoJan 23, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.