This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug sanitizer/81598] -fsanitize=enum does not detect range violation
- From: "marxin at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 03 Aug 2017 11:07:38 +0000
- Subject: [Bug sanitizer/81598] -fsanitize=enum does not detect range violation
- Auto-submitted: auto-generated
- References: <bug-81598-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81598
--- Comment #5 from Martin Liška <marxin at gcc dot gnu.org> ---
(In reply to Marek Polacek from comment #4)
> But you get compile-time warnings for that (-Wswitch), no?
For:
cat enum.c
enum values
{
A = 1000,
B = 30,
C = 100
};
int main(int argc, char **argv)
{
enum values x = (enum values)argc;
if (x == 12345)
return 1;
switch (x)
{
case A:
return 1;
case B:
return 1;
case C:
return 2;
case 123:
return 3;
default:
return 4;
}
}
I only have warning for 'case 123':
gcc -fsanitize=enum enum.c -Wall
enum.c: In function ‘main’:
enum.c:22:5: warning: case value ‘123’ not in enumerated type ‘enum values’
[-Wswitch]
case 123:
^~~~
But one could also produce warning for the if comparison and default bb in the
switch statement.