Re: [PATCH 2/2] parse-options: use and require int pointer for OPT_CMDMODE
- From
René Scharfe <l.s.r@web.de>
- Date
- Sep 11, 2023, 20:11 UTC
- Message-ID
- <54475801-0387-468e-bd90-a5ea0d677bca@web.de>
- In-Reply-To
- <xmqqedj4v808.fsf@gitster.g>
Am 11.09.23 um 21:12 schrieb Junio C Hamano:
Show 19 quoted lines
> René Scharfe <l.s.r@web.de> writes: > >> Some uses of OPT_CMDMODE provide a pointer to an enum. It is >> dereferenced as an int pointer in parse-options.c::get_value(). These >> two types are incompatible, though -- the storage size of an enum can >> vary between platforms. C23 would allow us to specify the underlying >> type of the different enums, making them compatible, but with C99 the >> easiest safe option is to actually use int as the value type. >> >> Convert the offending OPT_CMDMODE users and use the typed value_int >> point in the macro's definition to enforce that type for future ones. > > Interesting. I wondered if this means that applying [1/2] alone > will immediately break these places that [2/2] fixes, but the answer > is no, as the previous step did not make these places use the typed > pointer. But it also means that with this step alone to use "int", > instead of various "enum" types that can have representations that > are different from "int", would already "fix" the current code > while still casing back and forth from (void *)?
Yes and yes. And the change to use value_int on its own makes the type mismatch visible via compiler warnings. It guards against future violations.
René