[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <YtHJbckxy1FJ3ts7@carbon.gago.life>
Date: Fri, 15 Jul 2022 23:09:17 +0300
From: Petko Manolov <petko.manolov@...sulko.com>
To: linux-kernel@...r.kernel.org
Subject: GCC fails to spot uninitialized variable
Guys,
Today i was bitten by a stupid bug that i introduced myself while writing some
v4l2 code. Looking at it a bit more carefully i was surprised that GCC didn't
catch this one, as it was something that should definitely emit a warning.
When included into the driver, this particular code:
int blah(int a, int *b)
{
int ret;
switch (a) {
case 0:
ret = a;
break;
case 1:
ret = *b;
break;
case 2:
*b = a;
break;
default:
ret = 0;
}
return ret;
}
somehow managed to defeat GCC checks. Compiling it as a standalone .c file
with:
gcc -Wall -O2 -c t.c
gives me nice:
t.c:19:16: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
19 | return ret;
| ^~~
Any idea what might have gone wrong?
cheers,
Petko
Powered by blists - more mailing lists