extra, db: we have to record every function call in the db
[smatch.git] / check_return.c
blob038ea1be2ae90031382603b6149d582ff0c19dae
1 /*
2 * smatch/check_return.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #include "smatch.h"
11 #include "smatch_slist.h"
13 static int my_id;
15 static void must_check(const char *fn, struct expression *expr, void *data)
17 struct statement *stmt;
19 stmt = last_ptr_list((struct ptr_list *)big_statement_stack);
20 if (stmt->type == STMT_EXPRESSION && stmt->expression == expr)
21 sm_msg("warn: unchecked '%s'", fn);
24 static void register_must_check_funcs(void)
26 struct token *token;
27 const char *func;
28 static char name[256];
31 snprintf(name, 256, "%s.must_check_funcs", option_project_str);
32 name[255] = '\0';
33 token = get_tokens_file(name);
34 if (!token)
35 return;
36 if (token_type(token) != TOKEN_STREAMBEGIN)
37 return;
38 token = token->next;
39 while (token_type(token) != TOKEN_STREAMEND) {
40 if (token_type(token) != TOKEN_IDENT)
41 return;
42 func = show_ident(token->ident);
43 add_function_hook(func, &must_check, NULL);
44 token = token->next;
46 clear_token_alloc();
49 void check_return(int id)
51 my_id = id;
52 register_must_check_funcs();