File: | builds/wireshark/wireshark/epan/dfilter/sttype-op.c |
Warning: | line 73, column 14 Value stored to 's' during its initialization is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Wireshark - Network traffic analyzer |
3 | * By Gerald Combs <[email protected]> |
4 | * Copyright 2001 Gerald Combs |
5 | * |
6 | * |
7 | * SPDX-License-Identifier: GPL-2.0-or-later |
8 | */ |
9 | |
10 | #include "syntax-tree.h" |
11 | #include "sttype-op.h" |
12 | |
13 | typedef struct { |
14 | uint32_t magic; |
15 | stnode_op_t op; |
16 | stmatch_t how; |
17 | stnode_t *val1; |
18 | stnode_t *val2; |
19 | } oper_t; |
20 | |
21 | #define OPER_MAGIC0xab9009ba 0xab9009ba |
22 | |
23 | static void * |
24 | oper_new(void *junk _U___attribute__((unused))) |
25 | { |
26 | oper_t *oper; |
27 | |
28 | ws_assert(junk == NULL)do { if ((1) && !(junk == ((void*)0))) ws_log_fatal_full ("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c", 28, __func__ , "assertion failed: %s", "junk == ((void*)0)"); } while (0); |
29 | |
30 | oper = g_new(oper_t, 1)((oper_t *) g_malloc_n ((1), sizeof (oper_t))); |
31 | |
32 | oper->magic = OPER_MAGIC0xab9009ba; |
33 | oper->op = STNODE_OP_UNINITIALIZED; |
34 | oper->how = STNODE_MATCH_DEF; |
35 | oper->val1 = NULL((void*)0); |
36 | oper->val2 = NULL((void*)0); |
37 | |
38 | return oper; |
39 | } |
40 | |
41 | static void * |
42 | oper_dup(const void *data) |
43 | { |
44 | const oper_t *org = data; |
45 | oper_t *oper; |
46 | |
47 | oper = oper_new(NULL((void*)0)); |
48 | oper->op = org->op; |
49 | oper->how = org->how; |
50 | oper->val1 = stnode_dup(org->val1); |
51 | oper->val2 = stnode_dup(org->val2); |
52 | |
53 | return oper; |
54 | } |
55 | |
56 | static void |
57 | oper_free(void *value) |
58 | { |
59 | oper_t *oper = value; |
60 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 60, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 60, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
61 | |
62 | if (oper->val1) |
63 | stnode_free(oper->val1); |
64 | if (oper->val2) |
65 | stnode_free(oper->val2); |
66 | |
67 | g_free(oper); |
68 | } |
69 | |
70 | static char * |
71 | oper_todisplay(const oper_t *oper) |
72 | { |
73 | const char *s = "(notset)"; |
Value stored to 's' during its initialization is never read | |
74 | |
75 | switch(oper->op) { |
76 | case STNODE_OP_NOT: |
77 | s = "!"; |
78 | break; |
79 | case STNODE_OP_AND: |
80 | s = "&&"; |
81 | break; |
82 | case STNODE_OP_OR: |
83 | s = "||"; |
84 | break; |
85 | case STNODE_OP_ALL_EQ: |
86 | s = "==="; |
87 | break; |
88 | case STNODE_OP_ANY_EQ: |
89 | s = "=="; |
90 | break; |
91 | case STNODE_OP_ALL_NE: |
92 | s = "!="; |
93 | break; |
94 | case STNODE_OP_ANY_NE: |
95 | s = "~="; |
96 | break; |
97 | case STNODE_OP_GT: |
98 | s = ">"; |
99 | break; |
100 | case STNODE_OP_GE: |
101 | s = ">="; |
102 | break; |
103 | case STNODE_OP_LT: |
104 | s = "<"; |
105 | break; |
106 | case STNODE_OP_LE: |
107 | s = "<="; |
108 | break; |
109 | case STNODE_OP_BITWISE_AND: |
110 | s = "&"; |
111 | break; |
112 | case STNODE_OP_ADD: |
113 | s = "+"; |
114 | break; |
115 | case STNODE_OP_UNARY_MINUS: |
116 | case STNODE_OP_SUBTRACT: |
117 | s = "-"; |
118 | break; |
119 | case STNODE_OP_MULTIPLY: |
120 | s = "*"; |
121 | break; |
122 | case STNODE_OP_DIVIDE: |
123 | s = "/"; |
124 | break; |
125 | case STNODE_OP_MODULO: |
126 | s = "%"; |
127 | break; |
128 | case STNODE_OP_CONTAINS: |
129 | s = "contains"; |
130 | break; |
131 | case STNODE_OP_MATCHES: |
132 | s = "matches"; |
133 | break; |
134 | case STNODE_OP_IN: |
135 | s = "in"; |
136 | break; |
137 | case STNODE_OP_NOT_IN: |
138 | s = "not in"; |
139 | break; |
140 | case STNODE_OP_UNINITIALIZED: |
141 | s = "(uninitialized)"; |
142 | break; |
143 | } |
144 | return g_strdup(s)g_strdup_inline (s); |
145 | } |
146 | |
147 | static char * |
148 | oper_todebug(const oper_t *oper) |
149 | { |
150 | const char *s = stnode_op_name(oper->op); |
151 | if (oper->how == STNODE_MATCH_ALL) |
152 | return ws_strdup_printf("ALL %s", s)wmem_strdup_printf(((void*)0), "ALL %s", s); |
153 | if (oper->how == STNODE_MATCH_ANY) |
154 | return ws_strdup_printf("ANY %s", s)wmem_strdup_printf(((void*)0), "ANY %s", s); |
155 | return ws_strdup(s)wmem_strdup(((void*)0), s); |
156 | } |
157 | |
158 | static char * |
159 | oper_tostr(const void *value, bool_Bool pretty) |
160 | { |
161 | const oper_t *oper = value; |
162 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 162, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 162, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
163 | |
164 | if (pretty) |
165 | return oper_todisplay(oper); |
166 | return oper_todebug(oper); |
167 | } |
168 | |
169 | static int |
170 | num_operands(stnode_op_t op) |
171 | { |
172 | switch(op) { |
173 | case STNODE_OP_NOT: |
174 | case STNODE_OP_UNARY_MINUS: |
175 | return 1; |
176 | case STNODE_OP_AND: |
177 | case STNODE_OP_OR: |
178 | case STNODE_OP_ALL_EQ: |
179 | case STNODE_OP_ANY_EQ: |
180 | case STNODE_OP_ALL_NE: |
181 | case STNODE_OP_ANY_NE: |
182 | case STNODE_OP_GT: |
183 | case STNODE_OP_GE: |
184 | case STNODE_OP_LT: |
185 | case STNODE_OP_LE: |
186 | case STNODE_OP_BITWISE_AND: |
187 | case STNODE_OP_ADD: |
188 | case STNODE_OP_SUBTRACT: |
189 | case STNODE_OP_MULTIPLY: |
190 | case STNODE_OP_DIVIDE: |
191 | case STNODE_OP_MODULO: |
192 | case STNODE_OP_CONTAINS: |
193 | case STNODE_OP_MATCHES: |
194 | case STNODE_OP_IN: |
195 | case STNODE_OP_NOT_IN: |
196 | return 2; |
197 | case STNODE_OP_UNINITIALIZED: |
198 | ASSERT_STNODE_OP_NOT_REACHED(op)ws_log_fatal_full("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 198, __func__, "Invalid stnode op '%s'.", stnode_op_name(op )); |
199 | } |
200 | |
201 | ws_assert_not_reached()ws_log_fatal_full("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 201, __func__, "assertion \"not reached\" failed"); |
202 | } |
203 | |
204 | |
205 | void |
206 | sttype_oper_set1(stnode_t *node, stnode_op_t op, stnode_t *val1) |
207 | { |
208 | oper_t *oper = stnode_data(node); |
209 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 209, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 209, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
210 | |
211 | ws_assert(num_operands(op) == 1)do { if ((1) && !(num_operands(op) == 1)) ws_log_fatal_full ("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c", 211, __func__ , "assertion failed: %s", "num_operands(op) == 1"); } while ( 0); |
212 | oper->op = op; |
213 | oper->val1 = val1; |
214 | oper->val2 = NULL((void*)0); |
215 | } |
216 | |
217 | void |
218 | sttype_oper_set2(stnode_t *node, stnode_op_t op, stnode_t *val1, stnode_t *val2) |
219 | { |
220 | oper_t *oper = stnode_data(node); |
221 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 221, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 221, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
222 | |
223 | ws_assert(num_operands(op) == 2)do { if ((1) && !(num_operands(op) == 2)) ws_log_fatal_full ("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c", 223, __func__ , "assertion failed: %s", "num_operands(op) == 2"); } while ( 0); |
224 | oper->op = op; |
225 | oper->val1 = val1; |
226 | oper->val2 = val2; |
227 | } |
228 | |
229 | void |
230 | sttype_oper_set1_args(stnode_t *node, stnode_t *val1) |
231 | { |
232 | oper_t *oper; |
233 | |
234 | oper = (oper_t*)stnode_data(node); |
235 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 235, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 235, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
236 | |
237 | ws_assert(num_operands(oper->op) == 1)do { if ((1) && !(num_operands(oper->op) == 1)) ws_log_fatal_full ("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c", 237, __func__ , "assertion failed: %s", "num_operands(oper->op) == 1"); } while (0); |
238 | oper->val1 = val1; |
239 | oper->val2 = NULL((void*)0); |
240 | } |
241 | |
242 | void |
243 | sttype_oper_set2_args(stnode_t *node, stnode_t *val1, stnode_t *val2) |
244 | { |
245 | oper_t *oper; |
246 | |
247 | oper = (oper_t*)stnode_data(node); |
248 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 248, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 248, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
249 | |
250 | ws_assert(num_operands(oper->op) == 2)do { if ((1) && !(num_operands(oper->op) == 2)) ws_log_fatal_full ("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c", 250, __func__ , "assertion failed: %s", "num_operands(oper->op) == 2"); } while (0); |
251 | oper->val1 = val1; |
252 | oper->val2 = val2; |
253 | } |
254 | |
255 | void |
256 | sttype_oper_set_op(stnode_t *node, stnode_op_t op) |
257 | { |
258 | oper_t *oper = stnode_data(node); |
259 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 259, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 259, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
260 | ws_assert(oper->op == STNODE_OP_UNINITIALIZED)do { if ((1) && !(oper->op == STNODE_OP_UNINITIALIZED )) ws_log_fatal_full("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 260, __func__, "assertion failed: %s", "oper->op == STNODE_OP_UNINITIALIZED" ); } while (0); |
261 | oper->op = op; |
262 | } |
263 | |
264 | stnode_op_t |
265 | sttype_oper_get_op(stnode_t *node) |
266 | { |
267 | oper_t *oper = stnode_data(node); |
268 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 268, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 268, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
269 | return oper->op; |
270 | } |
271 | |
272 | void |
273 | sttype_oper_get(stnode_t *node, stnode_op_t *p_op, stnode_t **p_val1, stnode_t **p_val2) |
274 | { |
275 | oper_t *oper = stnode_data(node); |
276 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 276, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 276, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
277 | |
278 | if (p_op) |
279 | *p_op = oper->op; |
280 | if (p_val1) |
281 | *p_val1 = oper->val1; |
282 | if (p_val2) |
283 | *p_val2 = oper->val2; |
284 | } |
285 | |
286 | void |
287 | sttype_test_set_match(stnode_t *node, stmatch_t how) |
288 | { |
289 | oper_t *oper = stnode_data(node); |
290 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 290, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 290, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
291 | oper->how = how; |
292 | } |
293 | |
294 | stmatch_t |
295 | sttype_test_get_match(stnode_t *node) |
296 | { |
297 | oper_t *oper = stnode_data(node); |
298 | ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR , "epan/dfilter/sttype-op.c", 298, __func__, "assertion failed: %s" , "oper"); } while (0); if ((oper)->magic != (0xab9009ba)) { ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c" , 298, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08" "x", (oper)->magic, (0xab9009ba)); } } while(0); |
299 | return oper->how; |
300 | } |
301 | |
302 | void |
303 | sttype_register_opers(void) |
304 | { |
305 | static sttype_t test_type = { |
306 | STTYPE_TEST, |
307 | oper_new, |
308 | oper_free, |
309 | oper_dup, |
310 | oper_tostr |
311 | }; |
312 | static sttype_t arithmetic_type = { |
313 | STTYPE_ARITHMETIC, |
314 | oper_new, |
315 | oper_free, |
316 | oper_dup, |
317 | oper_tostr |
318 | }; |
319 | |
320 | sttype_register(&test_type); |
321 | sttype_register(&arithmetic_type); |
322 | } |
323 | |
324 | /* |
325 | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
326 | * |
327 | * Local variables: |
328 | * c-basic-offset: 8 |
329 | * tab-width: 8 |
330 | * indent-tabs-mode: t |
331 | * End: |
332 | * |
333 | * vi: set shiftwidth=8 tabstop=8 noexpandtab: |
334 | * :indentSize=8:tabSize=8:noTabs=false: |
335 | */ |