From: Dan Carpenter Date: Thu, 7 Feb 2013 06:55:23 +0000 (+0300) Subject: db: take static vs global into consideration wit function pointers X-Git-Tag: 1.57~2 X-Git-Url: https://repo.or.cz/w/smatch.git/commitdiff_plain/bba26aeafd6999994624b1ecc5c709992a972c0f db: take static vs global into consideration wit function pointers If we're going to save a function pointer to a static function it has to be done in the same file where the function is defined. Before it would say the function was called as a pointer when it wasn't and we'd think all kinds of bogus values passed were passed to it. This silences some false positives. Signed-off-by: Dan Carpenter --- diff --git a/smatch_db.c b/smatch_db.c index 964669cf..0f859add 100644 --- a/smatch_db.c +++ b/smatch_db.c @@ -344,9 +344,18 @@ static int get_ptr_name(void *unused, int argc, char **argv, char **azColName) static void get_function_pointer_callers(struct symbol *sym) { + char sql_filter[1024]; + + if (sym->ctype.modifiers & MOD_STATIC) { + snprintf(sql_filter, 1024, "file = '%s' and function = '%s';", + get_filename(), sym->ident->name); + } else { + snprintf(sql_filter, 1024, "function = '%s';", + sym->ident->name); + } + ptr_name = NULL; - run_sql(get_ptr_name, "select ptr from function_ptr where function = '%s'", - sym->ident->name); + run_sql(get_ptr_name, "select ptr from function_ptr where %s", sql_filter); if (!ptr_name) return;