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

Re: -Wunterminated-string-initialization warning with GCC 15 in object-file.c

From
Patrick Steinhardt <ps@pks.im>
Date
Nov 18, 2024, 07:40 UTC
Message-ID
<ZzrvecZnS-b0M-1p@pks.im>
In-Reply-To
<20241117090329.GA2341486@coredump.intra.peff.net>
On Sun, Nov 17, 2024 at 04:03:29AM -0500, Jeff King wrote:
Show 34 quoted lines
> On Sun, Nov 17, 2024 at 02:50:39AM +0000, Sam James wrote:
> 
> > With upcoming GCC 15, a new warning is added
> > (-Wunterminated-string-initialization) that fires when building git:
> > ```
> >     CC object-file.o
> > object-file.c:52:9: warning: initializer-string for array of ‘unsigned char’ is too long [-Wunterminated-string-initialization]
> >    52 |         "\x6e\xf1\x9b\x41\x22\x5c\x53\x69\xf1\xc1" \
> >       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > object-file.c:79:17: note: in expansion of macro ‘EMPTY_TREE_SHA256_BIN_LITERAL’
> >    79 |         .hash = EMPTY_TREE_SHA256_BIN_LITERAL,
> >       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > object-file.c:61:9: warning: initializer-string for array of ‘unsigned char’ is too long [-Wunterminated-string-initialization]
> >    61 |         "\x47\x3a\x0f\x4c\x3b\xe8\xa9\x36\x81\xa2" \
> >       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > object-file.c:83:17: note: in expansion of macro ‘EMPTY_BLOB_SHA256_BIN_LITERAL’
> >    83 |         .hash = EMPTY_BLOB_SHA256_BIN_LITERAL,
> >       |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > ```
> > 
> > Context for the new warning is at https://gcc.gnu.org/PR115185.
> 
> I think the warning is a false positive for us, but I don't begrudge
> them for adding it. It could definitely catch real problems.
> 
> Here are some patches. The first one should fix the warning (but I don't
> have gcc-15 handy to test!). Please let me know if it works for you (and
> thank you for reporting).
> 
> The others are cleanups and future-proofing I found in the same area.
> Not strictly required, but IMHO worth doing.
> 
> +cc brian since I think this is a continuation of some hash-algo
> cleanups he did earlier, plus he piped up in the other gcc-15 thread. ;)

I've got two comments, but other than that this looks like a nice cleanup to me. Thanks!

Patrick
Previous: Sam JamesNext: Jeff King
Message 16 of 25 in “-Wunterminated-string-initialization warning with GCC 15 in object-file.c”
  1. Sam JamesNov 17, 2024
  2. Jeff KingNov 17, 2024
  3. 1/5 object-file: prefer array-of-bytes initializer for hash literalsJeff King, Nov 17, 2024
  4. René ScharfeNov 17, 2024
  5. Jeff KingNov 18, 2024
  6. 2/5 object-file: drop confusing oid initializer of empty_tree structJeff King, Nov 17, 2024
  7. 3/5 object-file: move empty_tree struct into find_cached_object()Jeff King, Nov 17, 2024
  8. Patrick SteinhardtNov 18, 2024
  9. Jeff KingNov 18, 2024
  10. 4/5 object-file: drop oid field from find_cached_object() return valueJeff King, Nov 17, 2024
  11. 5/5 object-file: inline empty tree and blob literalsJeff King, Nov 17, 2024
  12. Patrick SteinhardtNov 18, 2024
  13. brian m. carlsonNov 17, 2024
  14. Jeff KingNov 18, 2024
  15. Sam JamesNov 18, 2024
  16. Patrick SteinhardtNov 18, 2024
  17. 0/6 -Wunterminated-string-initialization warning + cleanupsJeff King, Nov 18, 2024
  18. 1/6 object-file: prefer array-of-bytes initializer for hash literalsJeff King, Nov 18, 2024
  19. 2/6 object-file: drop confusing oid initializer of empty_tree structJeff King, Nov 18, 2024
  20. 3/6 object-file: move empty_tree struct into find_cached_object()Jeff King, Nov 18, 2024
  21. 4/6 object-file: drop oid field from find_cached_object() return valueJeff King, Nov 18, 2024
  22. 5/6 object-file: treat cached_object values as constJeff King, Nov 18, 2024
  23. 6/6 object-file: inline empty tree and blob literalsJeff King, Nov 18, 2024
  24. Patrick SteinhardtNov 18, 2024
  25. Junio C HamanoNov 18, 2024

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.