From 30eaa1cfb9290dd661cb25869e5f511ecf54604c Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 8 Dec 2011 10:57:52 +0300 Subject: [PATCH] db: pass &foo type parameter information to called functions If you have a struct declared on the stack, and you pass the address then the information about that was getting lost before. But with this patch passing &foo means that the information about foo.bar gets translated as $$->bar and passed properly. In the long term, Smatch needs to move to using memory locations instead of names like this. Signed-off-by: Dan Carpenter --- smatch_db.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/smatch_db.c b/smatch_db.c index bbafc0a8..1f9a2810 100644 --- a/smatch_db.c +++ b/smatch_db.c @@ -92,6 +92,13 @@ static void print_struct_members(char *fn, struct expression *expr, int param, s struct symbol *sym; int len; char printed_name[256]; + int is_address = 0; + + expr = strip_expr(expr); + if (expr->type == EXPR_PREOP && expr->op == '&') { + expr = strip_expr(expr->unop); + is_address = 1; + } name = get_variable_from_expr(expr, &sym); if (!name || !sym) @@ -103,7 +110,10 @@ static void print_struct_members(char *fn, struct expression *expr, int param, s continue; if (strncmp(name, sm->name, len) || sm->name[len] == '\0') continue; - snprintf(printed_name, sizeof(printed_name), "$$%s", sm->name + len); + if (is_address) + snprintf(printed_name, sizeof(printed_name), "$$->%s", sm->name + len + 1); + else + snprintf(printed_name, sizeof(printed_name), "$$%s", sm->name + len); callback(fn, param, printed_name, sm->state); } END_FOR_EACH_PTR(sm); free: -- 2.11.4.GIT