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

Re: [PATCH] mailinfo: resolve -Wstring-plus-int warning

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 23, 2014, 06:26 UTC
Message-ID
<CAPc5daUbXtNXSn8_tspvdF+SH5aeX+jVJTramtOm96Dc1wCqtg@mail.gmail.com>
In-Reply-To
<20140923060407.GA23861@peff.net>
On Mon, Sep 22, 2014 at 11:04 PM, Jeff King <peff@peff.net> wrote:
Show 9 quoted lines
>
> I don't mind silencing this one warning (even though I find it a little
> ridiculous). I'm slightly concerned that more brain-damage may be coming
> our way, but we can deal with that if it ever does.
>
> Like Junio, I prefer keeping strlen() rather than switching to sizeof,
> as it is less error-prone (no need for extra "-1" dance, and it won't
> silently do the wrong thing if the array is ever converted to a
> pointer).
I actually do not mind losing the sample[] array too much.

The early 45 bytes or so of that array (or a string constant) is not used by the code at all; I didn't want to count "From " (that's 5), 40-hex and then a SP -- ah, see, it is 46 bytes and I didn't want such miscounting. The only real contents that matter in that sample[] array is the tail part that is meant as the magic(5) cue. I'd be OK if the code checked the length of the line against a hardcoded constant and then did strcmp() starting from a hardcoded offset of the string and the magic cue string, and that would also avoid the warning from Eric's compiler.

But personally, I think the way it is coded is much easier to read, and is much harder to get it wrong while maintaining it. So...

Previous: Jeff KingNext: Jeff King
Message 5 of 12 in “mailinfo: resolve -Wstring-plus-int warning”
  1. mailinfo: resolve -Wstring-plus-int warningEric Sunshine, Sep 21, 2014
  2. Junio C HamanoSep 22, 2014
  3. Eric SunshineSep 22, 2014
  4. Jeff KingSep 23, 2014
  5. Junio C HamanoSep 23, 2014
  6. Jeff KingSep 23, 2014
  7. Eric SunshineSep 23, 2014
  8. Eric SunshineSep 23, 2014
  9. Eric SunshineSep 23, 2014
  10. Jeff KingSep 23, 2014
  11. Junio C HamanoSep 22, 2014
  12. Eric SunshineSep 22, 2014

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.