Re: [PATCH 08/12] skip_prefix(): check const match between in and out params
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Apr 1, 2026, 14:04 UTC
- Message-ID
- <b77be594-83b4-4d9b-9f89-569f1f335d61@gmail.com>
- In-Reply-To
- <14a417c6-fc80-4a7e-993d-57fff10896f8@gmail.com>
On 01/04/2026 14:17, Phillip Wood wrote:
Show 22 quoted lines
> On 01/04/2026 00:50, Jeff King wrote: >> >> +/* >> + * Check that an out-parameter that is "at least as const as" a matching >> + * in-parameter. For example, skip_prefix() will return "out" that is >> a subset >> + * of "str". So: >> + * >> + * const str, const out: ok >> + * non-const str, const out: ok >> + * non-const str, non-const out: ok >> + * const str, non-const out: compile error >> + * >> + * See the skip_prefix macro below for an example of use. >> + */ >> +#define CONST_OUTPARAM(in, out) \ >> + ((const char **)(0 ? ((*(out) = (in)),(out)) : (out))) >> +#define skip_prefix(str, prefix, out) \ >> + skip_prefix((str), (prefix), CONST_OUTPARAM((str), (out))) > > This is clever but it changes the behavior of skip_prefix() which is > documented as not touching out if it returns false.
Sorry, I've just realized we always take the other branch so this does not change the behavior and is in fact a nice solution to the problem.
Thanks
Phillip
Show 14 quoted lines
> That may not matter > in practice but there are nearly 600 callers so auditing them all would > be quite an undertaking. Elsewhere there was some discussion about using > type generic macros to fix the warnings. That would be more complex as > we need to check if they were supported by the compiler but it would > avoid changing the behavior. > > Thanks for working on fixing these warnings, your approach of trying to > fix the underlying problem rather than casting away the warning is very > welcome. > > Phillip > >