From: Petko Manolov <petko.manolov@konsulko.com>
To: linux-kernel@vger.kernel.org
Subject: GCC fails to spot uninitialized variable
Date: Fri, 15 Jul 2022 23:09:17 +0300 [thread overview]
Message-ID: <YtHJbckxy1FJ3ts7@carbon.gago.life> (raw)
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
next reply other threads:[~2022-07-15 20:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-15 20:09 Petko Manolov [this message]
2022-07-15 22:03 ` Nathan Chancellor
2022-07-16 6:25 ` Petko Manolov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YtHJbckxy1FJ3ts7@carbon.gago.life \
--to=petko.manolov@konsulko.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®