extra: don't reset impossible states after a condition
[smatch.git] / check_return.c
bloba343d2f2beb76497472cbcbc0231776327937a90
1 /*
2 * Copyright (C) 2010 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 #include "smatch.h"
19 #include "smatch_slist.h"
21 static int my_id;
23 static void must_check(const char *fn, struct expression *expr, void *data)
25 struct statement *stmt;
27 stmt = last_ptr_list((struct ptr_list *)big_statement_stack);
28 if (stmt->type == STMT_EXPRESSION && stmt->expression == expr)
29 sm_msg("warn: unchecked '%s'", fn);
32 static void register_must_check_funcs(void)
34 struct token *token;
35 const char *func;
36 static char name[256];
39 snprintf(name, 256, "%s.must_check_funcs", option_project_str);
40 name[255] = '\0';
41 token = get_tokens_file(name);
42 if (!token)
43 return;
44 if (token_type(token) != TOKEN_STREAMBEGIN)
45 return;
46 token = token->next;
47 while (token_type(token) != TOKEN_STREAMEND) {
48 if (token_type(token) != TOKEN_IDENT)
49 return;
50 func = show_ident(token->ident);
51 add_function_hook(func, &must_check, NULL);
52 token = token->next;
54 clear_token_alloc();
57 void check_return(int id)
59 my_id = id;
60 register_must_check_funcs();