buf_size: there was a mistake in handling calls to a function pointer
[smatch.git] / smatch_dinfo.c
blob414e2c859d48cf44405b1973f62229bcfb002a0c
1 /*
2 * smatch/smatch_dinfo.c
4 * Copyright (C) 2010 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
11 * smatch_dinfo.c has helper functions for handling data_info structs
15 #include <stdlib.h>
16 #ifndef __USE_ISOC99
17 #define __USE_ISOC99
18 #endif
19 #include <limits.h>
20 #include "parse.h"
21 #include "smatch.h"
22 #include "smatch_slist.h"
23 #include "smatch_extra.h"
25 struct data_range whole_range = {
26 .min = LLONG_MIN,
27 .max = LLONG_MAX,
30 static struct data_info *alloc_dinfo(void)
32 struct data_info *ret;
34 ret = __alloc_data_info(0);
35 ret->related = NULL;
36 ret->type = DATA_RANGE;
37 ret->value_ranges = NULL;
38 return ret;
41 static struct data_info *alloc_dinfo_range(long long min, long long max)
43 struct data_info *ret;
45 ret = alloc_dinfo();
46 add_range(&ret->value_ranges, min, max);
47 return ret;
50 static struct data_info *alloc_dinfo_range_list(struct range_list *rl)
52 struct data_info *ret;
54 ret = alloc_dinfo();
55 ret->value_ranges = rl;
56 return ret;
59 static struct data_info *clone_dinfo(struct data_info *dinfo)
61 struct data_info *ret;
63 ret = alloc_dinfo();
64 ret->related = clone_related_list(dinfo->related);
65 ret->value_ranges = clone_range_list(dinfo->value_ranges);
66 return ret;
69 struct smatch_state *clone_extra_state(struct smatch_state *state)
71 struct smatch_state *ret;
73 ret = __alloc_smatch_state(0);
74 ret->name = state->name;
75 ret->data = clone_dinfo(get_dinfo(state));
76 return ret;
79 struct smatch_state *alloc_extra_state_empty(void)
81 struct smatch_state *state;
82 struct data_info *dinfo;
84 dinfo = alloc_dinfo();
85 state = __alloc_smatch_state(0);
86 state->data = dinfo;
87 state->name = "";
88 return state;
91 static struct smatch_state *alloc_extra_state_no_name(int val)
93 struct smatch_state *state;
95 state = __alloc_smatch_state(0);
96 state->data = (void *)alloc_dinfo_range(val, val);
97 return state;
100 /* We do this because ->value_ranges is a list */
101 struct smatch_state *extra_undefined(void)
103 struct data_info *dinfo;
104 static struct smatch_state *ret;
105 static struct symbol *prev_func;
107 if (prev_func == cur_func_sym)
108 return ret;
109 prev_func = cur_func_sym;
111 dinfo = alloc_dinfo_range(whole_range.min, whole_range.max);
112 ret = __alloc_smatch_state(0);
113 ret->name = "unknown";
114 ret->data = dinfo;
115 return ret;
118 struct smatch_state *alloc_extra_state(long long val)
120 struct smatch_state *state;
122 state = alloc_extra_state_no_name(val);
123 state->name = show_ranges(get_dinfo(state)->value_ranges);
124 return state;
127 struct smatch_state *alloc_extra_state_range(long long min, long long max)
129 struct smatch_state *state;
131 if (min == whole_range.min && max == whole_range.max)
132 return extra_undefined();
133 state = __alloc_smatch_state(0);
134 state->data = (void *)alloc_dinfo_range(min, max);
135 state->name = show_ranges(get_dinfo(state)->value_ranges);
136 return state;
139 struct smatch_state *alloc_extra_state_range_list(struct range_list *rl)
141 struct smatch_state *state;
143 if (is_whole_range_rl(rl))
144 return extra_undefined();
146 state = __alloc_smatch_state(0);
147 state->data = (void *)alloc_dinfo_range_list(rl);
148 state->name = show_ranges(get_dinfo(state)->value_ranges);
149 return state;