Bug Summary

File:builds/wireshark/wireshark/epan/dfilter/sttype-op.c
Warning:line 74, column 14
Value stored to 's' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name sttype-op.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-18/lib/clang/18 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/epan/dfilter -I /builds/wireshark/wireshark/build/epan/dfilter -I /builds/wireshark/wireshark/epan -I /builds/wireshark/wireshark/tools/lemon -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-truncation -Wno-format-nonliteral -Wno-pointer-sign -std=gnu11 -ferror-limit 19 -fvisibility=hidden -fwrapv -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -dwarf-debug-flags /usr/lib/llvm-18/bin/clang -### --analyze -x c -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_BUILD_DLL -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/epan/dfilter -I /builds/wireshark/wireshark/build/epan/dfilter -I /builds/wireshark/wireshark/epan -I /builds/wireshark/wireshark/tools/lemon -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -fvisibility=hidden -fexcess-precision=fast -fstrict-flex-arrays=3 -fstack-clash-protection -fcf-protection=full -D _GLIBCXX_ASSERTIONS -fstack-protector-strong -fno-delete-null-pointer-checks -fno-strict-overflow -fno-strict-aliasing -fexceptions -Wno-format-truncation -Wno-format-nonliteral -fdiagnostics-color=always -Wno-pointer-sign -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -std=gnu11 -fPIC /builds/wireshark/wireshark/epan/dfilter/sttype-op.c -o /builds/wireshark/wireshark/sbout/2024-12-03-100307-3935-1 -Xclang -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /builds/wireshark/wireshark/sbout/2024-12-03-100307-3935-1 -x c /builds/wireshark/wireshark/epan/dfilter/sttype-op.c
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
13typedef 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
23static void *
24oper_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
41static void *
42oper_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 if (org->val2)
52 oper->val2 = stnode_dup(org->val2);
53
54 return oper;
55}
56
57static void
58oper_free(void *value)
59{
60 oper_t *oper = value;
61 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 61, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 61, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
62
63 if (oper->val1)
64 stnode_free(oper->val1);
65 if (oper->val2)
66 stnode_free(oper->val2);
67
68 g_free(oper);
69}
70
71static char *
72oper_todisplay(const oper_t *oper)
73{
74 const char *s = "(notset)";
Value stored to 's' during its initialization is never read
75
76 switch(oper->op) {
77 case STNODE_OP_NOT:
78 s = "!";
79 break;
80 case STNODE_OP_AND:
81 s = "&&";
82 break;
83 case STNODE_OP_OR:
84 s = "||";
85 break;
86 case STNODE_OP_ALL_EQ:
87 s = "===";
88 break;
89 case STNODE_OP_ANY_EQ:
90 s = "==";
91 break;
92 case STNODE_OP_ALL_NE:
93 s = "!=";
94 break;
95 case STNODE_OP_ANY_NE:
96 s = "~=";
97 break;
98 case STNODE_OP_GT:
99 s = ">";
100 break;
101 case STNODE_OP_GE:
102 s = ">=";
103 break;
104 case STNODE_OP_LT:
105 s = "<";
106 break;
107 case STNODE_OP_LE:
108 s = "<=";
109 break;
110 case STNODE_OP_BITWISE_AND:
111 s = "&";
112 break;
113 case STNODE_OP_ADD:
114 s = "+";
115 break;
116 case STNODE_OP_UNARY_MINUS:
117 case STNODE_OP_SUBTRACT:
118 s = "-";
119 break;
120 case STNODE_OP_MULTIPLY:
121 s = "*";
122 break;
123 case STNODE_OP_DIVIDE:
124 s = "/";
125 break;
126 case STNODE_OP_MODULO:
127 s = "%";
128 break;
129 case STNODE_OP_CONTAINS:
130 s = "contains";
131 break;
132 case STNODE_OP_MATCHES:
133 s = "matches";
134 break;
135 case STNODE_OP_IN:
136 s = "in";
137 break;
138 case STNODE_OP_NOT_IN:
139 s = "not in";
140 break;
141 case STNODE_OP_UNINITIALIZED:
142 s = "(uninitialized)";
143 break;
144 }
145 return g_strdup(s)g_strdup_inline (s);
146}
147
148static char *
149oper_todebug(const oper_t *oper)
150{
151 const char *s = stnode_op_name(oper->op);
152 if (oper->how == STNODE_MATCH_ALL)
153 return ws_strdup_printf("ALL %s", s)wmem_strdup_printf(((void*)0), "ALL %s", s);
154 if (oper->how == STNODE_MATCH_ANY)
155 return ws_strdup_printf("ANY %s", s)wmem_strdup_printf(((void*)0), "ANY %s", s);
156 return ws_strdup(s)wmem_strdup(((void*)0), s);
157}
158
159static char *
160oper_tostr(const void *value, bool_Bool pretty)
161{
162 const oper_t *oper = value;
163 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 163, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 163, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
164
165 if (pretty)
166 return oper_todisplay(oper);
167 return oper_todebug(oper);
168}
169
170static int
171num_operands(stnode_op_t op)
172{
173 switch(op) {
174 case STNODE_OP_NOT:
175 case STNODE_OP_UNARY_MINUS:
176 return 1;
177 case STNODE_OP_AND:
178 case STNODE_OP_OR:
179 case STNODE_OP_ALL_EQ:
180 case STNODE_OP_ANY_EQ:
181 case STNODE_OP_ALL_NE:
182 case STNODE_OP_ANY_NE:
183 case STNODE_OP_GT:
184 case STNODE_OP_GE:
185 case STNODE_OP_LT:
186 case STNODE_OP_LE:
187 case STNODE_OP_BITWISE_AND:
188 case STNODE_OP_ADD:
189 case STNODE_OP_SUBTRACT:
190 case STNODE_OP_MULTIPLY:
191 case STNODE_OP_DIVIDE:
192 case STNODE_OP_MODULO:
193 case STNODE_OP_CONTAINS:
194 case STNODE_OP_MATCHES:
195 case STNODE_OP_IN:
196 case STNODE_OP_NOT_IN:
197 return 2;
198 case STNODE_OP_UNINITIALIZED:
199 ASSERT_STNODE_OP_NOT_REACHED(op)ws_log_fatal_full("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 199, __func__, "Invalid stnode op '%s'.", stnode_op_name(op
))
;
200 }
201
202 ws_assert_not_reached()ws_log_fatal_full("", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 202, __func__, "assertion \"not reached\" failed")
;
203}
204
205
206void
207sttype_oper_set1(stnode_t *node, stnode_op_t op, stnode_t *val1)
208{
209 oper_t *oper = stnode_data(node);
210 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 210, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 210, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
211
212 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", 212, __func__
, "assertion failed: %s", "num_operands(op) == 1"); } while (
0)
;
213 oper->op = op;
214 oper->val1 = val1;
215 oper->val2 = NULL((void*)0);
216}
217
218void
219sttype_oper_set2(stnode_t *node, stnode_op_t op, stnode_t *val1, stnode_t *val2)
220{
221 oper_t *oper = stnode_data(node);
222 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 222, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 222, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
223
224 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", 224, __func__
, "assertion failed: %s", "num_operands(op) == 2"); } while (
0)
;
225 oper->op = op;
226 oper->val1 = val1;
227 oper->val2 = val2;
228}
229
230void
231sttype_oper_set1_args(stnode_t *node, stnode_t *val1)
232{
233 oper_t *oper;
234
235 oper = (oper_t*)stnode_data(node);
236 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 236, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 236, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
237
238 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", 238, __func__
, "assertion failed: %s", "num_operands(oper->op) == 1"); }
while (0)
;
239 oper->val1 = val1;
240 oper->val2 = NULL((void*)0);
241}
242
243void
244sttype_oper_set2_args(stnode_t *node, stnode_t *val1, stnode_t *val2)
245{
246 oper_t *oper;
247
248 oper = (oper_t*)stnode_data(node);
249 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 249, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 249, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
250
251 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", 251, __func__
, "assertion failed: %s", "num_operands(oper->op) == 2"); }
while (0)
;
252 oper->val1 = val1;
253 oper->val2 = val2;
254}
255
256void
257sttype_oper_set_op(stnode_t *node, stnode_op_t op)
258{
259 oper_t *oper = stnode_data(node);
260 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 260, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 260, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
261 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"
, 261, __func__, "assertion failed: %s", "oper->op == STNODE_OP_UNINITIALIZED"
); } while (0)
;
262 oper->op = op;
263}
264
265stnode_op_t
266sttype_oper_get_op(stnode_t *node)
267{
268 oper_t *oper = stnode_data(node);
269 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 269, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 269, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
270 return oper->op;
271}
272
273void
274sttype_oper_get(stnode_t *node, stnode_op_t *p_op, stnode_t **p_val1, stnode_t **p_val2)
275{
276 oper_t *oper = stnode_data(node);
277 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 277, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 277, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
278
279 if (p_op)
280 *p_op = oper->op;
281 if (p_val1)
282 *p_val1 = oper->val1;
283 if (p_val2)
284 *p_val2 = oper->val2;
285}
286
287void
288sttype_test_set_match(stnode_t *node, stmatch_t how)
289{
290 oper_t *oper = stnode_data(node);
291 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 291, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 291, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
292 oper->how = how;
293}
294
295stmatch_t
296sttype_test_get_match(stnode_t *node)
297{
298 oper_t *oper = stnode_data(node);
299 ws_assert_magic(oper, OPER_MAGIC)do { do { if ((1) && !(oper)) ws_log_fatal_full("", LOG_LEVEL_ERROR
, "epan/dfilter/sttype-op.c", 299, __func__, "assertion failed: %s"
, "oper"); } while (0); if ((oper)->magic != (0xab9009ba))
{ ws_log_full("DFilter", LOG_LEVEL_ERROR, "epan/dfilter/sttype-op.c"
, 299, __func__, "Magic num is 0x%08" "x"", " "but should be 0x%08"
"x", (oper)->magic, (0xab9009ba)); } } while(0)
;
300 return oper->how;
301}
302
303void
304sttype_register_opers(void)
305{
306 static sttype_t test_type = {
307 STTYPE_TEST,
308 oper_new,
309 oper_free,
310 oper_dup,
311 oper_tostr
312 };
313 static sttype_t arithmetic_type = {
314 STTYPE_ARITHMETIC,
315 oper_new,
316 oper_free,
317 oper_dup,
318 oper_tostr
319 };
320
321 sttype_register(&test_type);
322 sttype_register(&arithmetic_type);
323}
324
325/*
326 * Editor modelines - https://www.wireshark.org/tools/modelines.html
327 *
328 * Local variables:
329 * c-basic-offset: 8
330 * tab-width: 8
331 * indent-tabs-mode: t
332 * End:
333 *
334 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
335 * :indentSize=8:tabSize=8:noTabs=false:
336 */