math: ignore fuzzy maxes that are type_min() + 1
[smatch.git] / check_propagate.c
blob74ae3e7436d2d4c5945d9ec29a632fd615cacd2b
1 /*
2 * smatch/check_propagate.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
11 * People should just return the error codes they received
12 * instead of making up there own dumb error codes all the time.
15 #include "smatch.h"
17 static int my_id;
19 static struct expression *last_return;
20 static struct expression *last_func;
22 static char *get_fn_name(struct expression *expr)
24 if (expr->type != EXPR_CALL)
25 return NULL;
26 if (expr->fn->type != EXPR_SYMBOL)
27 return NULL;
28 return get_variable_from_expr(expr->fn, NULL);
31 static void match_call_assignment(struct expression *expr)
33 if (get_macro_name(expr->left->pos))
34 return;
35 last_return = expr->left;
36 last_func = expr->right;
39 static void match_unset(struct expression *expr)
41 last_return = NULL;
44 static void match_return(struct expression *ret_value)
46 sval_t rval;
47 sval_t lret;
48 char *name;
50 if (!get_value(ret_value, &rval) || rval.value >= 0)
51 return;
52 if (get_implied_value(last_return, &lret))
53 return;
54 if (!get_implied_max(last_return, &lret) || lret.value >= 0)
55 return;
56 if (get_implied_min(last_return, &lret))
57 return;
58 name = get_variable_from_expr(last_return, NULL);
59 sm_msg("info: why not propagate '%s' from %s() instead of %s?",
60 name, get_fn_name(last_func), sval_to_str(rval));
61 free_string(name);
64 void check_propagate(int id)
66 if (option_project != PROJ_KERNEL)
67 return;
69 my_id = id;
70 add_hook(&match_unset, ASSIGNMENT_HOOK);
71 add_hook(&match_call_assignment, CALL_ASSIGNMENT_HOOK);
72 add_hook(&match_return, RETURN_HOOK);