From 2570cc3856da1260e1263b0eca892a576b2b3020 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Tue, 10 Jan 2017 22:36:01 +0300 Subject: [PATCH] function_hooks: change order of how db verse implied returns are handled The code here is sort of legacy stuff where we have three different ways of determining the return value. The issue with this patch concerns the way strlen() is handled. We set that up in smatch_common_functions.c where we have some custom code to say what the return value is. That code should over write what the DB says so it should happen after we do the stuff with the db. Signed-off-by: Dan Carpenter --- smatch_function_hooks.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/smatch_function_hooks.c b/smatch_function_hooks.c index 7b8b0f47..cc8071ff 100644 --- a/smatch_function_hooks.c +++ b/smatch_function_hooks.c @@ -857,21 +857,31 @@ static void match_assign_call(struct expression *expr) } fn = right->fn->symbol->ident->name; + call_backs = search_callback(func_hash, (char *)fn); /* - * some of these conflict (they try to set smatch extra twice), so we - * call them in order from least important to most important. + * The ordering here is sort of important. + * One example, of how this matters is that when we do: + * + * len = strlen(str); + * + * That is handled by smatch_common_functions.c and smatch_strlen.c. + * They use implied_return and function_assign_hook respectively. + * We want to get the implied return first before we do the function + * assignment hook otherwise we end up writing the wrong thing for len + * in smatch_extra.c because we assume that it already holds the + * strlen() when we haven't set it yet. */ - call_backs = search_callback(func_hash, (char *)fn); - call_call_backs(call_backs, ASSIGN_CALL, fn, expr); - if (db_return_states_assign(expr) == 1) handled = 1; else handled = assign_ranged_funcs(fn, expr, call_backs); handled |= handle_implied_return(expr); + + call_call_backs(call_backs, ASSIGN_CALL, fn, expr); + if (handled) return; -- 2.11.4.GIT