On Thu, 30 Jan 2025, 09:00 Dmitry Antipov, <dmanti...@yandex.ru> wrote:

> With (probably) -Wmaybe-uninitialized and/or -Wextra, shouldn't the
> compiler emit
> warning about possibly uninitialized 'y' passed to 'ddd()' in the example
> below?
>

Warnings are always going to be somewhat unreliable. You need a proper
static analyser to detect all problems on all possible paths (-fanalyzer
might do better here, I didn't check).



> struct T {
>    int a;
>    int b;
> };
>
> extern int bbb (struct T *, int *);
> extern int ccc (struct T *, int *);
> extern int ddd (struct T *, int);
>
> int
> aaa (struct T *t)
> {
>    int x = 0, y;         /* 'y' is uninitialized */
>
>    if (t->a)             /* if this condition is true */
>      goto l;
>
>    x += bbb (t, &y);
>
>   l:
>    if (t->b)             /* and this condition is false */
>        x += ccc (t, &y);
>
>    x += ddd (t, y);      /* then 'y' is passed to ddd() uninitialized */
>
>    return x;
> }
>
> Dmitry
>
>

Reply via email to