aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2014-04-23 00:05:04 -0400
committerAnders Broman <a.broman58@gmail.com>2014-04-23 04:44:59 +0000
commit0f90397d290cfb5add4b5303cec0247cf53cc2dc (patch)
tree77a9ddf213559d56ad05041ecfb4896d7f271de9 /tools
parent867a1827e7dc88896ee27a107eb35c4b3973d270 (diff)
Fix generator to remove Dead Store (Dead assignement/Dead increment) warning found by Clang.
(not sure why, but regeneration also "moved" some hf_ variables from previous version) Change-Id: I197eacbb3f892dbdca6e6bc354fc88240c1bfb34 Reviewed-on: https://code.wireshark.org/review/1291 Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/wireshark_gen.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/tools/wireshark_gen.py b/tools/wireshark_gen.py
index e7ba0d5468..e8448be6d4 100755
--- a/tools/wireshark_gen.py
+++ b/tools/wireshark_gen.py
@@ -1446,8 +1446,19 @@ class wireshark_gen_C:
if (st.kind() == idltype.tk_enum):
std = st.decl()
self.st.out(self.template_comment_union_code_discriminant, uname=std.repoId() )
- self.st.out(self.template_union_code_save_discriminant_enum, discname=un.identifier() )
- self.addvar(self.c_s_disc + un.identifier() + ";")
+
+ #count the number of cases to ensure variable is needed
+ num = 0
+ num_defaults = 0
+ for uc in un.cases(): # for all UnionCase objects in this union
+ num += len(uc.labels())
+ for cl in uc.labels():
+ if cl.default():
+ num_defaults += 1
+
+ if ((num != 1) or (num_defaults != 1)):
+ self.st.out(self.template_union_code_save_discriminant_enum, discname=un.identifier() )
+ self.addvar(self.c_s_disc + un.identifier() + ";")
elif (st.kind() == idltype.tk_long):
self.st.out(self.template_union_code_save_discriminant_long, discname=un.identifier() )