Avoid triggering a division by zero in the overflow check
authorBart Van Assche <bvanassche@acm.org>
Wed, 6 Feb 2013 14:10:11 +0000 (6 15:10 +0100)
committerDan Carpenter <dan.carpenter@oracle.com>
Wed, 6 Feb 2013 14:16:55 +0000 (6 17:16 +0300)
Avoid that expressions like 7 >> (8 * 0) trigger a division by zero error message.

This patch fixes a bug introduced in commit 48c2cc03bc3a50de2aaa70ff09cdeef8d03dab2e.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
smatch_sval.c

index 5fd7ca6..c1911f5 100644 (file)
@@ -447,9 +447,8 @@ int sval_binop_overflows(sval_t left, int op, sval_t right)
                        return 1;
                return 0;
        case '*':
-               if (sval_cmp(left, sval_binop(max, '/', right)) > 0)
-                       return 1;
-               return 0;
+               return right.value != 0 &&
+                       sval_cmp(left, sval_binop(max, '/', right)) > 0;
        }
        return 0;
 }