Make validation test harder.
[smatch.git] / check_err_ptr.c
blobd2ce331ff1987f75ce49f0123d2f4209a5ba36f8
1 /*
2 * sparse/check_err_ptr.c
4 * Copyright (C) 2009 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 /*
11 * Functions should never return both NULL and ERR_PTR().
14 #include "smatch.h"
15 #include "smatch_slist.h"
17 static int my_id;
19 static struct symbol *this_func;
20 static int err_ptr = 0;
21 static int returns_null = 0;
23 static void match_function_def(struct symbol *sym)
25 this_func = sym;
28 static void match_err_ptr(const char *fn, struct expression *expr, void *info)
30 if (!err_ptr)
31 smatch_msg("info: returns_err_ptr");
32 err_ptr = 1;
35 static void match_return(struct statement *stmt)
37 if (get_implied_value(stmt->ret_value) != 0)
38 return;
39 if (!returns_null)
40 smatch_msg("info: returns_null");
41 returns_null = 1;
44 static void match_end_func(struct symbol *sym)
46 err_ptr = 0;
47 returns_null = 0;
50 void check_err_ptr(int id)
52 my_id = id;
53 add_hook(&match_function_def, FUNC_DEF_HOOK);
54 add_function_hook("ERR_PTR", &match_err_ptr, NULL);
55 add_hook(&match_return, RETURN_HOOK);
56 add_hook(&match_end_func, END_FUNC_HOOK);