Add a header that redefines g_array_index() to throw in a "void *" cast

to work around the "data" field of a GArray being a guint8 *, and
defines a g_array_data() macro to extract that field and cast it to void
*.

Use that header where needed.

svn path=/trunk/; revision=21627
This commit is contained in:
Guy Harris 2007-04-30 19:24:25 +00:00
parent db53f99cca
commit 1d73cea470
7 changed files with 54 additions and 46 deletions

View File

@ -135,6 +135,7 @@ LIBWIRESHARK_INCLUDES = \
follow.h \
frame_data.h \
funnel.h \
garrayfix.h \
gcp.h \
gnuc_format_check.h \
greproto.h \

View File

@ -64,6 +64,7 @@
#include <epan/tap.h>
#include <epan/addr_resolv.h>
#include <epan/emem.h>
#include <epan/garrayfix.h>
#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);

View File

@ -51,6 +51,7 @@
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/strutil.h>
#include <epan/garrayfix.h>
#include <math.h>
@ -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);
}
}

View File

@ -52,6 +52,7 @@
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/strutil.h>
#include <epan/garrayfix.h>
#include "packet-rmt-norm.h"
#include <math.h>
@ -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); */

View File

@ -45,6 +45,7 @@
#include "packet-nfs.h"
#include <epan/tap.h>
#include <epan/strutil.h>
#include <epan/garrayfix.h>
/*
* See:

View File

@ -52,6 +52,7 @@
#include <epan/report_err.h>
#include <epan/filesystem.h>
#include <epan/prefs.h>
#include <epan/garrayfix.h>
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",

38
epan/garrayfix.h Normal file
View File

@ -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 <gerald@wireshark.org>
* 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__ */