From 5a902998bafa0bb679cced5314c0a5f70f7cc4fa Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 18 Apr 2012 15:52:06 +0300 Subject: [PATCH] math: handle __smatch_implied(&x); It should recognize that &x is a valid pointer. Ampersands are actually more complicated and subtle than to just say it's a valid pointer. But for now lets see how this works. Signed-off-by: Dan Carpenter --- smatch.h | 2 ++ smatch_math.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/smatch.h b/smatch.h index 7cf8857a..9092e618 100644 --- a/smatch.h +++ b/smatch.h @@ -315,6 +315,8 @@ struct data_range { long long max; }; extern struct data_range whole_range; +static const long long valid_ptr_max = LONG_MAX; +static const long long valid_ptr_min = 4096; /* smatch_states.c */ void __push_fake_cur_slist(); diff --git a/smatch_math.c b/smatch_math.c index f6c3a52a..0fbef222 100644 --- a/smatch_math.c +++ b/smatch_math.c @@ -89,11 +89,26 @@ static long long handle_expression_statement(struct expression *expr, int *undef return BOGUS; } +static long long handle_ampersand(int *undefined, int implied) +{ + if (implied == IMPLIED_MIN || implied == FUZZYMIN) + return valid_ptr_min; + if (implied == IMPLIED_MAX || implied == FUZZYMAX) + return valid_ptr_max; + + *undefined = 1; + return BOGUS; + +} + static long long handle_preop(struct expression *expr, int *undefined, int implied) { long long ret = BOGUS; switch (expr->op) { + case '&': + ret = handle_ampersand(undefined, implied); + break; case '!': ret = !_get_value(expr->unop, undefined, implied); break; -- 2.11.4.GIT