From: Dan Carpenter Date: Thu, 27 Jun 2013 08:03:25 +0000 (+0300) Subject: comparison: stop caring so much about wrapping (it's rare) X-Git-Tag: 1.59~34 X-Git-Url: https://repo.or.cz/w/smatch.git/commitdiff_plain/61792987c9e43a859a1cf191f7967b2efa9968e1 comparison: stop caring so much about wrapping (it's rare) If we have code like: a = b + 1; Then it's possible that "b + 1" might wrap, but it's more likely that it won't so lets say that "a > b". Signed-off-by: Dan Carpenter --- diff --git a/smatch_comparison.c b/smatch_comparison.c index 7e13c35d..6c136e51 100644 --- a/smatch_comparison.c +++ b/smatch_comparison.c @@ -564,29 +564,18 @@ static void match_assign_add(struct expression *expr) r_left = strip_expr(right->left); r_right = strip_expr(right->right); - if (!is_capped(expr->left)) { - get_absolute_max(r_left, &left_tmp); - get_absolute_max(r_right, &right_tmp); - if (sval_binop_overflows(left_tmp, '+', right_tmp)) - return; - } - get_absolute_min(r_left, &left_tmp); - if (sval_is_negative(left_tmp)) - return; get_absolute_min(r_right, &right_tmp); - if (sval_is_negative(right_tmp)) - return; - if (left_tmp.value == 0) - add_comparison(expr->left, SPECIAL_GTE, r_right); - else + if (left_tmp.value > 0) add_comparison(expr->left, '>', r_right); + else if (left_tmp.value == 0) + add_comparison(expr->left, SPECIAL_GTE, r_right); - if (right_tmp.value == 0) - add_comparison(expr->left, SPECIAL_GTE, r_left); - else + if (right_tmp.value > 0) add_comparison(expr->left, '>', r_left); + else if (right_tmp.value == 0) + add_comparison(expr->left, SPECIAL_GTE, r_left); } static void match_assign_sub(struct expression *expr) diff --git a/validation/sm_compare8.c b/validation/sm_compare8.c new file mode 100644 index 00000000..87b5d641 --- /dev/null +++ b/validation/sm_compare8.c @@ -0,0 +1,17 @@ +#include "check_debug.h" + +void *a, *b; +static int options_write(void) +{ + a = b + 1; + __smatch_compare(a, b); +} + +/* + * check-name: smatch compare #8 + * check-command: smatch -I.. sm_compare8.c + * + * check-output-start +sm_compare8.c:7 options_write() a > b + * check-output-end + */