diff --git a/epan/Makefile.common b/epan/Makefile.common index e633057e19..2192e9a4eb 100644 --- a/epan/Makefile.common +++ b/epan/Makefile.common @@ -135,6 +135,7 @@ LIBWIRESHARK_INCLUDES = \ follow.h \ frame_data.h \ funnel.h \ + garrayfix.h \ gcp.h \ gnuc_format_check.h \ greproto.h \ diff --git a/epan/dissectors/packet-radius.c b/epan/dissectors/packet-radius.c index c01246766a..0474818204 100644 --- a/epan/dissectors/packet-radius.c +++ b/epan/dissectors/packet-radius.c @@ -64,6 +64,7 @@ #include #include #include +#include #include "packet-radius.h" @@ -1492,13 +1493,13 @@ proto_register_radius(void) dict->vendors_by_name = g_hash_table_new(g_str_hash,g_str_equal); } - radius_vendors = (value_string*)(void *)ri.vend_vs->data; + radius_vendors = (value_string*)g_array_data(ri.vend_vs); proto_radius = proto_register_protocol("Radius Protocol", "RADIUS", "radius"); register_dissector("radius", dissect_radius, proto_radius); - proto_register_field_array(proto_radius,(hf_register_info*)(void *)(ri.hf->data),ri.hf->len); - proto_register_subtree_array((gint**)(void *)(ri.ett->data), ri.ett->len); + proto_register_field_array(proto_radius,(hf_register_info*)g_array_data(ri.hf),ri.hf->len); + proto_register_subtree_array((gint**)g_array_data(ri.ett), ri.ett->len); register_init_routine(&radius_init_protocol); diff --git a/epan/dissectors/packet-rmt-lct.c b/epan/dissectors/packet-rmt-lct.c index 8c1ff9c02e..aa9361f7b2 100644 --- a/epan/dissectors/packet-rmt-lct.c +++ b/epan/dissectors/packet-rmt-lct.c @@ -51,6 +51,7 @@ #include #include #include +#include #include @@ -461,27 +462,8 @@ void lct_dissector(struct _lct_ptr l, struct _fec_ptr f, tvbuff_t *tvb, proto_tr lct_ext_tree = NULL; /* Add the extensions to the subtree */ - for (i = 0; i < l.lct->ext->len; i++) { - /* - * The data member of a GArray isn't a void *, as - * it should be; it's a guint8 *, so GCC will - * warn about attempts to cast it to the type of - * an array member if -Wcast-align is specified. - * - * The code in GLib that allocates the data - * presumably arranges that it's aligned - * strictly enough for any data type (as that's - * how most memory allocators work), so that warning - * is bogus. - * - * We work around this by not using g_array_index(), - * but doing the indexing ourselves, and casting - * to the data pointer to void * first. - */ - struct _ext *ext_array = (void *)l.lct->ext->data; - - lct_ext_decode(&ext_array[i], l.prefs, tvb, lct_ext_tree, l.ett->ext_ext, f); - } + for (i = 0; i < l.lct->ext->len; i++) + lct_ext_decode(&g_array_index(l.lct->ext, struct _ext, i), l.prefs, tvb, lct_ext_tree, l.ett->ext_ext, f); } } diff --git a/epan/dissectors/packet-rmt-norm.c b/epan/dissectors/packet-rmt-norm.c index b03b680c75..f0c570b3fd 100644 --- a/epan/dissectors/packet-rmt-norm.c +++ b/epan/dissectors/packet-rmt-norm.c @@ -52,6 +52,7 @@ #include #include #include +#include #include "packet-rmt-norm.h" #include @@ -227,24 +228,7 @@ static guint dissect_norm_hdrext(struct _norm *norm, struct _fec_ptr *f, proto_t /* Add the extensions to the subtree */ for (i = 0; i < ext->len; i++) { - /* - * The data member of a GArray isn't a void *, as - * it should be; it's a guint8 *, so GCC will - * warn about attempts to cast it to the type of - * an array member if -Wcast-align is specified. - * - * The code in GLib that allocates the data - * presumably arranges that it's aligned - * strictly enough for any data type (as that's - * how most memory allocators work), so that warning - * is bogus. - * - * We work around this by not using g_array_index(), - * but doing the indexing ourselves, and casting - * to the data pointer to void * first. - */ - struct _ext *ext_array = (void *)ext->data; - struct _ext *e = &ext_array[i]; + struct _ext *e = &g_array_index(ext, struct _ext, i); lct_ext_decode(e, &lctp, tvb, ext_tree, ett.hdrext, *f); /* fec_decode_ext_fti(e, tvb, ext_tree, ett.hdrext, *f); */ diff --git a/epan/dissectors/packet-rpc.c b/epan/dissectors/packet-rpc.c index 3a585144a5..b40a26bb7e 100644 --- a/epan/dissectors/packet-rpc.c +++ b/epan/dissectors/packet-rpc.c @@ -45,6 +45,7 @@ #include "packet-nfs.h" #include #include +#include /* * See: diff --git a/epan/dissectors/packet-xml.c b/epan/dissectors/packet-xml.c index dbd1d3d00d..7173e904cf 100644 --- a/epan/dissectors/packet-xml.c +++ b/epan/dissectors/packet-xml.c @@ -52,6 +52,7 @@ #include #include #include +#include typedef struct _xml_ns_t { /* the name of this namespace */ @@ -1050,8 +1051,8 @@ next_attribute: add_xml_field(hfs, &root_element->hf_cdata, root_element->name, root_element->fqn); root_element->hf_tag = proto_register_protocol(dtd_data->description, dtd_data->proto_name, dtd_data->proto_name); - proto_register_field_array(root_element->hf_tag, (hf_register_info*)hfs->data, hfs->len); - proto_register_subtree_array((gint**)etts->data, etts->len); + proto_register_field_array(root_element->hf_tag, (hf_register_info*)g_array_data(hfs), hfs->len); + proto_register_subtree_array((gint**)g_array_data(etts), etts->len); if (dtd_data->media_type) { g_hash_table_insert(media_types,dtd_data->media_type,root_element); @@ -1218,8 +1219,8 @@ proto_register_xml(void) { xml_ns.hf_tag = proto_register_protocol("eXtensible Markup Language", "XML", xml_ns.name); - proto_register_field_array(xml_ns.hf_tag, (hf_register_info*)hf_arr->data, hf_arr->len); - proto_register_subtree_array((gint**)ett_arr->data, ett_arr->len); + proto_register_field_array(xml_ns.hf_tag, (hf_register_info*)g_array_data(hf_arr), hf_arr->len); + proto_register_subtree_array((gint**)g_array_data(ett_arr), ett_arr->len); xml_module = prefs_register_protocol(xml_ns.hf_tag,apply_prefs); prefs_register_bool_preference(xml_module, "heuristic", "Use Heuristics", diff --git a/epan/garrayfix.h b/epan/garrayfix.h new file mode 100644 index 0000000000..06d88073e5 --- /dev/null +++ b/epan/garrayfix.h @@ -0,0 +1,38 @@ +/* garrayfix.h + * Macros to work around the "data" field of a GArray having type guint8 *, + * rather than void *, so that, even though the GArray code should be + * ensuring that the data is aligned strictly enough for any data type, + * we still get warnings with -Wcast-align. + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GARRAYFIX_H__ +#define __GARRAYFIX_H__ + +#ifdef g_array_index +#undef g_array_index +#define g_array_index(a,t,i) (((t*) (void*) (a)->data) [(i)]) +#endif + +#define g_array_data(a) ((void*) (a)->data) + +#endif /* __GARRAYFIX_H__ */