math: overflows in hard max are undefined
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 23 Nov 2012 11:51:50 +0000 (23 14:51 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Fri, 23 Nov 2012 11:51:50 +0000 (23 14:51 +0300)
If the calculation overflows then by definition, it's sort of not a hard
max.

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

index c022db8..6e57a3d 100644 (file)
@@ -284,10 +284,15 @@ static sval_t handle_binop(struct expression *expr, int *undefined, int implied)
        switch (implied) {
        case IMPLIED_MAX:
        case FUZZY_MAX:
-       case HARD_MAX:
        case ABSOLUTE_MAX:
                if (sval_binop_overflows(left, expr->op, right))
                        return sval_type_max(get_type(expr));
+               break;
+       case HARD_MAX:
+               if (sval_binop_overflows(left, expr->op, right)) {
+                       *undefined = 1;
+                       return bogus;
+               }
        }
 
        switch (expr->op) {