db: take static vs global into consideration wit function pointers
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 7 Feb 2013 06:55:23 +0000 (7 09:55 +0300)
committerDan Carpenter <dan.carpenter@oracle.com>
Thu, 7 Feb 2013 06:55:23 +0000 (7 09:55 +0300)
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 <dan.carpenter@oracle.com>
smatch_db.c

index 964669c..0f859ad 100644 (file)
@@ -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;