flow: fix parsing known switch statements
commit9125b8047ad1e9eb41c90b182dbaff0e240b1a48
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 3 Aug 2022 14:30:34 +0000 (3 17:30 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Wed, 3 Aug 2022 14:30:34 +0000 (3 17:30 +0300)
treed3a0daad8bdc0be17d6500ce2b6bfaa80af494bc
parent4cd1f2430c10fdc56c3a514fc09a8013ebf7fdfc
flow: fix parsing known switch statements

The problem is that this code was ignoring the ->case_statement pointer
which is the first statement after a case statement.  It can be a block
as in the following example code:

switch (2) {
case 2: {
frob(); frob(); frob();
break;
}
...

We need to parse the first statement (which can be block statement with
other statements inside) and then check for if the __path_is_null().

This code is still not perfect.  If the default statement comes first it
assumes that it is a match.  Also Smatch needs to handle impossible paths
better for switch statements.  I don't think that's handled correctly...

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch_flow.c