From 7d7d745ea592f5ce2d3d2d2e1c1bb26ac773354b Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 20 May 2013 20:33:26 +0300 Subject: [PATCH] math: introduce handle_mod_rl() It's a little bit smarter than the original because if the left side is smaller than the right then it handles that. Signed-off-by: Dan Carpenter --- smatch_math.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/smatch_math.c b/smatch_math.c index 3834f04b..ac56b6c7 100644 --- a/smatch_math.c +++ b/smatch_math.c @@ -373,6 +373,33 @@ bogus: return bogus; } +static struct range_list *handle_mod_rl(struct expression *expr, int implied) +{ + struct range_list *rl; + sval_t left, right, sval; + + if (implied == EXACT) { + if (!get_value(expr->right, &right)) + return NULL; + if (!get_value(expr->left, &left)) + return NULL; + sval = sval_binop(left, '%', right); + return alloc_rl(sval, sval); + } + /* if we can't figure out the right side it's probably hopeless */ + if (!get_implied_value(expr->right, &right)) + return NULL; + + right = sval_cast(get_type(expr), right); + right.value--; + + rl = _get_rl(expr->left, implied); + if (rl && rl_max(rl).uvalue < right.uvalue) + right.uvalue = rl_max(rl).uvalue; + + return alloc_rl(zero, right); +} + static sval_t handle_mod(struct expression *expr, int *undefined, int implied) { sval_t left, right; @@ -417,10 +444,7 @@ static struct range_list *handle_binop_rl(struct expression *expr, int implied) switch (expr->op) { case '%': - ret = handle_mod(expr, &undefined, implied); - if (undefined) - return NULL; - return alloc_rl(ret, ret); + return handle_mod_rl(expr, implied); case '&': if (implied == HARD_MAX) return NULL; -- 2.11.4.GIT