From 3db5365e36907eba44b4e14a9b56cad273da67ac Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 25 Jan 2018 17:10:26 +0300 Subject: [PATCH] type_val: record fewer "unknown" assignments There are two bugs fixed here: foo = bar; This was setting foo->inner->value to unknown. The second bug was that "ptr++" was setting ptr->value to unknown. Signed-off-by: Dan Carpenter --- smatch_type_val.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/smatch_type_val.c b/smatch_type_val.c index 4606a61b..88244379 100644 --- a/smatch_type_val.c +++ b/smatch_type_val.c @@ -272,22 +272,31 @@ static int is_ignored_function(void) return 0; } -static int is_uncasted_function(void) +static int is_uncasted_pointer_assign(void) { struct expression *expr; struct symbol *left_type, *right_type; expr = get_faked_expression(); - if (!expr || expr->type != EXPR_ASSIGNMENT) + if (!expr) return 0; - if (expr->right->type != EXPR_CALL) + if (expr->type == EXPR_PREOP || expr->type == EXPR_POSTOP) { + if (expr->op == SPECIAL_INCREMENT || expr->op == SPECIAL_DECREMENT) + return 1; + } + if (expr->type != EXPR_ASSIGNMENT) return 0; left_type = get_type(expr->left); right_type = get_type(expr->right); if (!left_type || !right_type) return 0; - if (left_type->type != SYM_PTR || right_type->type != SYM_PTR) + + if (left_type->type != SYM_PTR && + left_type->type != SYM_ARRAY) + return 0; + if (right_type->type != SYM_PTR && + right_type->type != SYM_ARRAY) return 0; left_type = get_real_base_type(left_type); right_type = get_real_base_type(right_type); @@ -399,7 +408,7 @@ static void match_assign_value(struct expression *expr) goto free; if (is_ignored_function()) goto free; - if (is_uncasted_function()) + if (is_uncasted_pointer_assign()) goto free; if (is_uncasted_fn_param_from_db()) goto free; -- 2.11.4.GIT