impossible: handle switch statements
commitd8de82488c0ff935f0c2db6d2ab2848895a0f08d
authorDan Carpenter <dan.carpenter@oracle.com>
Wed, 27 Apr 2016 14:33:47 +0000 (27 17:33 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Wed, 27 Apr 2016 14:33:47 +0000 (27 17:33 +0300)
tree5a342ef4c7ebe9a39fd6e597e577315f0a990ef5
parent3209fb689a39c0bdd2ff75eb2469ab995ea09eb6
impossible: handle switch statements

One common situation is that you have a switch statement with no:

default:
return -EINVAL;

or whatever, so it looks like you could have a path through the code where
some bad thing happened.  The programmer knows that's impossible but Smatch
was not marking it that way.

This patch tries to fix that.

First of all no one was using the CASE_HOOK and there was a comment that I
was thinking about deleting it because it was passing nonsense data anyway.
I have repurposed it to pass the range list of the switch expression.  That
meant I had to move it from smatch_flow.c to smatch_implied.c.  If the
range_list it empty that means the case is impossible.

The other thing that I did is that if there is a switch statement with no
default case, then just fake one at the end.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
smatch.h
smatch_flow.c
smatch_hooks.c
smatch_implied.c
smatch_impossible.c
validation/sm_impossible3.c [new file with mode: 0644]