-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_propagate.c
73 lines (62 loc) · 1.54 KB
/
check_propagate.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
/*
* smatch/check_propagate.c
*
* Copyright (C) 2010 Dan Carpenter.
*
* Licensed under the Open Software License version 1.1
*
*/
/*
* People should just return the error codes they received
* instead of making up there own dumb error codes all the time.
*/
#include "smatch.h"
static int my_id;
static struct expression *last_return;
static struct expression *last_func;
static char *get_fn_name(struct expression *expr)
{
if (expr->type != EXPR_CALL)
return NULL;
if (expr->fn->type != EXPR_SYMBOL)
return NULL;
return expr_to_var(expr->fn);
}
static void match_call_assignment(struct expression *expr)
{
if (get_macro_name(expr->left->pos))
return;
last_return = expr->left;
last_func = expr->right;
}
static void match_unset(struct expression *expr)
{
last_return = NULL;
}
static void match_return(struct expression *ret_value)
{
sval_t rval;
sval_t lret;
char *name;
if (!get_value(ret_value, &rval) || rval.value >= 0)
return;
if (get_implied_value(last_return, &lret))
return;
if (!get_implied_max(last_return, &lret) || lret.value >= 0)
return;
if (get_implied_min(last_return, &lret) && !sval_is_min(lret))
return;
name = expr_to_var(last_return);
sm_msg("info: why not propagate '%s' from %s() instead of %s?",
name, get_fn_name(last_func), sval_to_str(rval));
free_string(name);
}
void check_propagate(int id)
{
if (option_project != PROJ_KERNEL)
return;
my_id = id;
add_hook(&match_unset, ASSIGNMENT_HOOK);
add_hook(&match_call_assignment, CALL_ASSIGNMENT_HOOK);
add_hook(&match_return, RETURN_HOOK);
}