Ethereal-dev: Re: [Ethereal-dev] Some compiler warnings

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Joerg Mayer <jmayer@xxxxxxxxx>
Date: Sat, 6 Dec 2003 20:20:53 +0100
On Fri, Dec 05, 2003 at 05:48:12PM +0100, Biot Olivier wrote:
> packet-m2pa.c:430: warning: dereferencing type-punned pointer will break
> strict-aliasing rules
> packet-m3ua.c:1749: warning: dereferencing type-punned pointer will break
> strict-aliasing rules
> packet-mtp3.c:494: warning: dereferencing type-punned pointer will break
> strict-aliasing rules

I've had the attached patch sitting in my sources for a few months. It
"fixes" the warnings, by changing the enums into gints. The fact that
I haven't committed them is, I don't like the solution and wanted to
check whether changing the parameter to guint would a) solve the problem
and b) be doable but haven't found the time since. If anyone wants to
try, do so :-)

 Ciao
      Jörg

-- 
Joerg Mayer                                           <jmayer@xxxxxxxxx>
We are stuck with technology when what we really want is just stuff that
works. Some say that should read Microsoft instead of technology.
Index: packet-m2pa.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-m2pa.c,v
retrieving revision 1.22
diff -p -u -r1.22 packet-m2pa.c
--- packet-m2pa.c	4 Sep 2003 14:32:34 -0000	1.22
+++ packet-m2pa.c	6 Dec 2003 19:12:23 -0000
@@ -79,7 +79,7 @@ typedef enum {
   M2PA_V9 = 2
 } Version_Type;
 
-static Version_Type m2pa_version = M2PA_V9;
+static gint m2pa_version = M2PA_V9;
 
 #define VERSION_LENGTH         1
 #define SPARE_LENGTH           1
@@ -427,7 +427,7 @@ proto_register_m2pa(void)
 
   m2pa_module = prefs_register_protocol(proto_m2pa, proto_reg_handoff_m2pa);
 
-  prefs_register_enum_preference(m2pa_module, "version", "M2PA version", "Version used by Ethereal", (gint *)&m2pa_version, m2pa_version_options, FALSE);
+  prefs_register_enum_preference(m2pa_module, "version", "M2PA version", "Version used by Ethereal", &m2pa_version, m2pa_version_options, FALSE);
   prefs_register_uint_preference(m2pa_module, "port", "M2PA SCTP Port", "Set the port for M2PA messages (Default of 3565)", 10, &global_sctp_port);
 }
 
Index: packet-m3ua.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-m3ua.c,v
retrieving revision 1.36
diff -p -u -r1.36 packet-m3ua.c
--- packet-m3ua.c	6 Oct 2003 20:46:51 -0000	1.36
+++ packet-m3ua.c	6 Dec 2003 19:12:23 -0000
@@ -305,7 +305,7 @@ typedef enum {
   M3UA_RFC
 } Version_Type;
 
-static Version_Type version = M3UA_RFC;
+static gint version = M3UA_RFC;
 
 static void
 dissect_parameters(tvbuff_t *, packet_info *, proto_tree *, proto_tree *);
@@ -1746,7 +1746,7 @@ proto_register_m3ua(void)
   /* Register the protocol name and description */
   proto_m3ua = proto_register_protocol("MTP 3 User Adaptation Layer", "M3UA",  "m3ua");
   m3ua_module = prefs_register_protocol(proto_m3ua, NULL);
-  prefs_register_enum_preference(m3ua_module, "version", "M3UA Version", "Version used by Ethereal", (gint *)&version, options, FALSE);
+  prefs_register_enum_preference(m3ua_module, "version", "M3UA Version", "Version used by Ethereal", &version, options, FALSE);
 
   /* Required function calls to register the header fields and subtrees used */
   proto_register_field_array(proto_m3ua, hf, array_length(hf));
Index: packet-mtp3.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-mtp3.c,v
retrieving revision 1.23
diff -p -u -r1.23 packet-mtp3.c
--- packet-mtp3.c	3 Dec 2003 22:50:41 -0000	1.23
+++ packet-mtp3.c	6 Dec 2003 19:12:24 -0000
@@ -80,7 +80,7 @@ static gint ett_mtp3_label_opc = -1;
 static dissector_table_t mtp3_sio_dissector_table;
 
 #include <packet-mtp3.h>
-Standard_Type mtp3_standard = ITU_STANDARD;
+gint mtp3_standard = ITU_STANDARD;
 
 static gboolean mtp3_use_ansi_5_bit_sls = FALSE;
 
@@ -491,7 +491,7 @@ proto_register_mtp3(void)
 
   prefs_register_enum_preference(mtp3_module, "standard", "MTP3 standard",
 				 "The SS7 standard used in MTP3 packets",
-				 (gint *)&mtp3_standard, mtp3_options, FALSE);
+				 &mtp3_standard, mtp3_options, FALSE);
 
   prefs_register_bool_preference(mtp3_module, "ansi_5_bit_sls",
 				 "Use 5-bit SLS (ANSI only)",
Index: packet-mtp3.h
===================================================================
RCS file: /usr/local/cvsroot/ethereal/packet-mtp3.h,v
retrieving revision 1.3
diff -p -u -r1.3 packet-mtp3.h
--- packet-mtp3.h	10 Apr 2003 18:52:11 -0000	1.3
+++ packet-mtp3.h	6 Dec 2003 19:12:24 -0000
@@ -27,7 +27,7 @@ typedef enum {
   CHINESE_ITU_STANDARD = 3
 } Standard_Type;
 
-extern Standard_Type mtp3_standard;
+extern gint mtp3_standard;
 
 #define ITU_PC_LENGTH     2
 #define ITU_PC_MASK       0x3FFF