extra: type bug handling for loops
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 15 Mar 2013 19:36:37 +0000 (15 22:36 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Fri, 15 Mar 2013 19:36:37 +0000 (15 22:36 +0300)
This code was using the type of the limiter in the for condition as the
type for the iterator.

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

index bcff0a2..e476901 100644 (file)
@@ -226,7 +226,9 @@ static struct sm_state *handle_canonical_for_inc(struct expression *iter_expr,
                return NULL;
        if (!estate_get_single_value(sm->state, &start))
                return NULL;
-       if (!get_implied_max(condition->right, &end))
+       if (get_implied_max(condition->right, &end))
+               end = sval_cast(get_type(iter_var), end);
+       else
                end = sval_type_max(get_type(iter_var));
 
        if (get_sm_state_expr(SMATCH_EXTRA, condition->left) != sm)