Re: [PATCH] Fix maybe-uninitialized warnings found by gcc 9 -flto
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 5, 2019, 17:56 UTC
- Message-ID
- <xmqqd0ger5j7.fsf@gitster-ct.c.googlers.com>
- In-Reply-To
- <20190905082459.26816-1-s-beyer@gmx.net>
Stephan Beyer <s-beyer@gmx.net> writes:
Show 13 quoted lines
> diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c
> index 7e79b555de..ef0963e2f4 100644
> --- a/t/helper/test-read-cache.c
> +++ b/t/helper/test-read-cache.c
> @@ -4,7 +4,7 @@
>
> int cmd__read_cache(int argc, const char **argv)
> {
> - int i, cnt = 1, namelen;
> + int i, cnt = 1, namelen = 0;
> const char *name = NULL;
>
> if (argc > 1 && skip_prefix(argv[1], "--print-and-refresh=", &name)) {namelen = strlen(name);
The above is the only assignment to namelen in this function, and namelen is used like so:
if (name) {
...
pos = index_name_pos(&the_index, name, namelen);So somebody does not realize that skip_prefix() returns true only when it touches name. But skip_prefix() is inline and visible to the compiler, and it is quite clear that name is only touched when the function returns non-zero.
static inline int skip_prefix(const char *str, const char *prefix,
const char **out)
{
do {
if (!*prefix) {
*out = str;
return 1;
}
} while (*str++ == *prefix++);
return 0;
}So it looks like it is another case of compiler getting confused.