From 10fe85a486a5e587beb06165c0756fc8c035f44b Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 10 Jun 2015 13:44:18 +0300 Subject: [PATCH] extra: handle x = (u8)y; correctly If we do a truncate cast then that should be reflected when we handle the assignment. Currently we just strip the cast away. When this was introduced, I said that I changed "how casts are handled" but I think it is an "improvement". Which is terribly vague and it's obviously not correct to ignore casts... Fixes: 1dcfc9fdad6d ('extra: shuffle match_assign a bit') Signed-off-by: Dan Carpenter --- smatch_extra.c | 4 ++-- validation/sm_casts7.c | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 validation/sm_casts7.c diff --git a/smatch_extra.c b/smatch_extra.c index 5c262628..d965d888 100644 --- a/smatch_extra.c +++ b/smatch_extra.c @@ -669,9 +669,9 @@ static void match_assign(struct expression *expr) left = strip_expr(expr->left); - right = strip_expr(expr->right); + right = strip_parens(expr->right); while (right->type == EXPR_ASSIGNMENT && right->op == '=') - right = strip_expr(right->left); + right = strip_parens(right->left); if (expr->op == '=' && is_condition(expr->right)) return; /* handled in smatch_condition.c */ diff --git a/validation/sm_casts7.c b/validation/sm_casts7.c new file mode 100644 index 00000000..355007a5 --- /dev/null +++ b/validation/sm_casts7.c @@ -0,0 +1,24 @@ +#include +#include +#include "check_debug.h" + +int a; +int main(void) +{ + int x; + + a = (unsigned short)x; + __smatch_implied(a); + + return 0; +} + + +/* + * check-name: smatch: casts #7 + * check-command: smatch -I.. sm_casts7.c + * + * check-output-start +sm_casts7.c:11 main() implied: a = '0-65535' + * check-output-end + */ -- 2.11.4.GIT