]> Kevux Git Server - rit/commit
config: store allocated string in non-const pointer
authorJeff King <peff@peff.net>
Thu, 26 Mar 2026 19:23:20 +0000 (15:23 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Mar 2026 19:47:17 +0000 (12:47 -0700)
commitd385845d55e0e3a775fc47ac8d73a5ec41308db3
tree8d84f5e690c66a852ce6afebf067e79f82df0067
parent213b2138770d820bc28fde839f3e4df90a5d5d81
config: store allocated string in non-const pointer

When git-config matches a url, we copy the variable section name and
store it in the "section" member of a urlmatch_config struct. That
member is const, since the url-matcher will not touch it (and other
callers really will have a const string).

But that means that we have only a const pointer to our allocated
string. We have to cast away the constness when we free it, and likewise
when we assign NUL to tie off the "." separating the subsection and key.
This latter happens implicitly via a strchr() call, but recent versions
of glibc have added annotations that let the compiler detect that and
complain.

Let's keep our own "section" pointer for the non-const string, and then
just point config.section at it. That avoids all of the casting, both
explicit and implicit.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/config.c