/
smatch_project.c
163 lines (140 loc) · 3.47 KB
/
smatch_project.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
* sparse/smatch_project.c
*
* Copyright (C) 2010 Dan Carpenter.
*
* Licensed under the Open Software License version 1.1
*
*/
/*
* This file is only for very generic stuff, that is reusable
* between projects. If you need something special create a
* check_your_project.c.
*
*/
#include "smatch.h"
#include "smatch_extra.h"
#include "smatch_function_hashtable.h"
static DEFINE_HASHTABLE_INSERT(insert_func, char, int);
static DEFINE_HASHTABLE_SEARCH(search_func, char, int);
static struct hashtable *silenced_funcs;
static struct hashtable *no_inline_funcs;
int is_silenced_function(void)
{
char *func;
func = get_function();
if (!func)
return 0;
if (search_func(silenced_funcs, func))
return 1;
return 0;
}
int is_no_inline_function(const char *function)
{
if (search_func(no_inline_funcs, (char *)function))
return 1;
return 0;
}
static void register_no_return_funcs(void)
{
struct token *token;
const char *func;
char name[256];
if (option_project == PROJ_NONE)
strcpy(name, "no_return_funcs");
else
snprintf(name, 256, "%s.no_return_funcs", option_project_str);
token = get_tokens_file(name);
if (!token)
return;
if (token_type(token) != TOKEN_STREAMBEGIN)
return;
token = token->next;
while (token_type(token) != TOKEN_STREAMEND) {
if (token_type(token) != TOKEN_IDENT)
return;
func = show_ident(token->ident);
add_function_hook(func, &__match_nullify_path_hook, NULL);
token = token->next;
}
clear_token_alloc();
}
static void register_ignored_macros(void)
{
struct token *token;
char *macro;
char name[256];
if (option_project == PROJ_NONE)
strcpy(name, "ignored_macros");
else
snprintf(name, 256, "%s.ignored_macros", option_project_str);
token = get_tokens_file(name);
if (!token)
return;
if (token_type(token) != TOKEN_STREAMBEGIN)
return;
token = token->next;
while (token_type(token) != TOKEN_STREAMEND) {
if (token_type(token) != TOKEN_IDENT)
return;
macro = alloc_string(show_ident(token->ident));
add_ptr_list(&__ignored_macros, macro);
token = token->next;
}
clear_token_alloc();
}
static void register_silenced_functions(void)
{
struct token *token;
char *func;
char name[256];
silenced_funcs = create_function_hashtable(500);
if (option_project == PROJ_NONE)
return;
snprintf(name, 256, "%s.silenced_functions", option_project_str);
token = get_tokens_file(name);
if (!token)
return;
if (token_type(token) != TOKEN_STREAMBEGIN)
return;
token = token->next;
while (token_type(token) != TOKEN_STREAMEND) {
if (token_type(token) != TOKEN_IDENT)
return;
func = alloc_string(show_ident(token->ident));
insert_func(silenced_funcs, func, INT_PTR(1));
token = token->next;
}
clear_token_alloc();
}
static void register_no_inline_functions(void)
{
struct token *token;
char *func;
char name[256];
no_inline_funcs = create_function_hashtable(500);
if (option_project == PROJ_NONE)
return;
snprintf(name, 256, "%s.no_inline_functions", option_project_str);
token = get_tokens_file(name);
if (!token)
return;
if (token_type(token) != TOKEN_STREAMBEGIN)
return;
token = token->next;
while (token_type(token) != TOKEN_STREAMEND) {
if (token_type(token) != TOKEN_IDENT)
return;
func = alloc_string(show_ident(token->ident));
insert_func(no_inline_funcs, func, INT_PTR(1));
token = token->next;
}
clear_token_alloc();
}
void register_project(int id)
{
register_no_return_funcs();
register_ignored_macros();
register_silenced_functions();
register_no_inline_functions();
}