Skip to content

Commit

Permalink
capped: handle for loops better
Browse files Browse the repository at this point in the history
The smatch_capped.c stuff only counts variable caps.  So if a value is
capped at 10, that's smatch_extra.c that's not smatch_capped.  This code
says that if either side of the if statement is known then it's not
capped.

But at the start of a for loop the iterator is zero so it's known.  In
other words, this basically ignored for loops, but actually for loops
make things capped.

Signed-off-by: Dan Carpenter <[email protected]>
  • Loading branch information
Dan Carpenter committed May 8, 2023
1 parent bdc3514 commit 03c0545
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions smatch_capped.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,14 @@ static void match_condition(struct expression *expr)
left = strip_expr(left->left);

/* If we're dealing with known expressions, that's for smatch_extra.c */
if (get_implied_value(left, &sval) ||
get_implied_value(right, &sval))
return;
if (__in_pre_condition) {
if (get_implied_value(right, &sval))
return;
} else {
if (get_implied_value(left, &sval) ||
get_implied_value(right, &sval))
return;
}

switch (expr->op) {
case '<':
Expand Down

0 comments on commit 03c0545

Please sign in to comment.