19 * Say we have a line like:
20 * foo = bar / 8;
21 * Assume we don't know anything about bar. Well, now we know that foo is less
22 * than UINT_MAX / 8. Which might be useful, but it probably is misleading
23 * useless knowledge. Up to now we have ignored those but now we have said to
24 * store them.
25 *
26 * It also works if you have something like "foo = (int)(char)unknown_var;".
27 *
28 * I feel like this data doesn't have to be perfect, it just has to be better
29 * than nothing and that will help eliminate some false positives.
30 *
31 */
32
33 #include "smatch.h"
34 #include "smatch_slist.h"
35 #include "smatch_extra.h"
36
37 static int my_id;
38
39 static void extra_mod_hook(const char *name, struct symbol *sym, struct expression *expr, struct smatch_state *state)
40 {
41 struct smatch_state *abs;
42 struct range_list *rl;
43
44 abs = get_state(my_id, name, sym);
45 if (!abs || !estate_rl(abs))
46 return;
47 rl = rl_intersection(estate_rl(abs), estate_rl(state));
48 set_state(my_id, name, sym, alloc_estate_rl(clone_rl(rl)));
49 }
50
51 static void pre_merge_hook(struct sm_state *cur, struct sm_state *other)
52 {
53 struct smatch_state *extra;
54 struct range_list *rl;
55
56 extra = get_state(SMATCH_EXTRA, cur->name, cur->sym);
57 if (!extra || !estate_rl(extra))
58 return;
|
19 * Say we have a line like:
20 * foo = bar / 8;
21 * Assume we don't know anything about bar. Well, now we know that foo is less
22 * than UINT_MAX / 8. Which might be useful, but it probably is misleading
23 * useless knowledge. Up to now we have ignored those but now we have said to
24 * store them.
25 *
26 * It also works if you have something like "foo = (int)(char)unknown_var;".
27 *
28 * I feel like this data doesn't have to be perfect, it just has to be better
29 * than nothing and that will help eliminate some false positives.
30 *
31 */
32
33 #include "smatch.h"
34 #include "smatch_slist.h"
35 #include "smatch_extra.h"
36
37 static int my_id;
38
39 void set_real_absolute(struct expression *expr, struct smatch_state *state)
40 {
41 set_state_expr(my_id, expr, clone_estate(state));
42 }
43
44 static void extra_mod_hook(const char *name, struct symbol *sym, struct expression *expr, struct smatch_state *state)
45 {
46 struct smatch_state *abs;
47 struct range_list *rl;
48
49 abs = get_state(my_id, name, sym);
50 if (!abs || !estate_rl(abs))
51 return;
52 rl = rl_intersection(estate_rl(abs), estate_rl(state));
53 set_state(my_id, name, sym, alloc_estate_rl(clone_rl(rl)));
54 }
55
56 static void pre_merge_hook(struct sm_state *cur, struct sm_state *other)
57 {
58 struct smatch_state *extra;
59 struct range_list *rl;
60
61 extra = get_state(SMATCH_EXTRA, cur->name, cur->sym);
62 if (!extra || !estate_rl(extra))
63 return;
|