Start assigning ett_ values at 0, rather than 1; get rid of the reserved
ETT_NONE entry. Initialize the "tree_type" field of a "field_info" structure to -1, meaning "this has not been given a subtree". Add checks before using that field that it's in range. That way, you have to create a subtree before putting protocol tree items under another item. We allocate the "tree_is_expanded" array when we've registered all dissectors; there's no need to allocate it while we're registering dissectors and, in fact, doing so means we leak memory (the memory for the version we allocated while registering dissectors). svn path=/trunk/; revision=5068
This commit is contained in:
parent
d1f2aaf8ac
commit
5de2533f2d
23
epan/proto.c
23
epan/proto.c
|
@ -1,7 +1,7 @@
|
|||
/* proto.c
|
||||
* Routines for protocol tree
|
||||
*
|
||||
* $Id: proto.c,v 1.58 2002/03/19 08:42:16 guy Exp $
|
||||
* $Id: proto.c,v 1.59 2002/04/01 02:00:52 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -215,12 +215,6 @@ proto_init(const char *plugin_dir,void (register_all_protocols)(void),
|
|||
|
||||
gpa_hfinfo = g_ptr_array_new();
|
||||
|
||||
/* Allocate "tree_is_expanded", with one element for ETT_NONE,
|
||||
and initialize that element to FALSE. */
|
||||
tree_is_expanded = g_malloc(sizeof (gint));
|
||||
tree_is_expanded[0] = FALSE;
|
||||
num_tree_types = 1;
|
||||
|
||||
/* Initialize the ftype subsystem */
|
||||
ftypes_initialize();
|
||||
|
||||
|
@ -1664,7 +1658,7 @@ alloc_field_info(proto_tree *tree, int hfindex, tvbuff_t *tvb, gint start,
|
|||
fi->start += tvb_raw_offset(tvb);
|
||||
}
|
||||
fi->length = *length;
|
||||
fi->tree_type = ETT_NONE;
|
||||
fi->tree_type = -1;
|
||||
fi->visible = PTREE_DATA(tree)->visible;
|
||||
fi->representation = NULL;
|
||||
|
||||
|
@ -2073,23 +2067,14 @@ proto_register_subtree_array(gint **indices, int num_indices)
|
|||
int i;
|
||||
gint **ptr = indices;
|
||||
|
||||
/*
|
||||
* Add "num_indices" elements to "tree_is_expanded".
|
||||
*/
|
||||
tree_is_expanded = g_realloc(tree_is_expanded,
|
||||
(num_tree_types + num_indices)*sizeof (gint));
|
||||
|
||||
/*
|
||||
* Assign "num_indices" subtree numbers starting at "num_tree_types",
|
||||
* returning the indices through the pointers in the array whose
|
||||
* first element is pointed to by "indices", set to FALSE the
|
||||
* elements to which those subtree numbers refer, and update
|
||||
* first element is pointed to by "indices", and update
|
||||
* "num_tree_types" appropriately.
|
||||
*/
|
||||
for (i = 0; i < num_indices; i++, ptr++, num_tree_types++) {
|
||||
tree_is_expanded[num_tree_types] = FALSE;
|
||||
for (i = 0; i < num_indices; i++, ptr++, num_tree_types++)
|
||||
**ptr = num_tree_types;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* proto.h
|
||||
* Definitions for protocol display
|
||||
*
|
||||
* $Id: proto.h,v 1.28 2002/02/18 01:08:42 guy Exp $
|
||||
* $Id: proto.h,v 1.29 2002/04/01 02:00:52 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -556,10 +556,7 @@ extern void proto_registrar_dump(void);
|
|||
|
||||
/* Points to the first element of an array of Booleans, indexed by
|
||||
a subtree item type; that array element is TRUE if subtrees of
|
||||
an item of that type are to be expanded.
|
||||
|
||||
ETT_NONE is reserved for unregistered subtree types. */
|
||||
#define ETT_NONE 0
|
||||
an item of that type are to be expanded. */
|
||||
extern gboolean *tree_is_expanded;
|
||||
|
||||
/* Number of elements in that array. */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* proto_draw.c
|
||||
* Routines for GTK+ packet display
|
||||
*
|
||||
* $Id: proto_draw.c,v 1.49 2002/03/31 23:11:04 guy Exp $
|
||||
* $Id: proto_draw.c,v 1.50 2002/04/01 02:00:53 guy Exp $
|
||||
*
|
||||
* Ethereal - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@ethereal.com>
|
||||
|
@ -166,6 +166,7 @@ expand_tree(GtkCTree *ctree, GtkCTreeNode *node, gpointer user_data _U_)
|
|||
|
||||
finfo = gtk_ctree_node_get_row_data( ctree, node);
|
||||
g_assert(finfo);
|
||||
g_assert(finfo->tree_type >= 0 && finfo->tree_type < num_tree_types);
|
||||
|
||||
val = &tree_is_expanded[finfo->tree_type];
|
||||
*val = TRUE;
|
||||
|
@ -179,6 +180,7 @@ collapse_tree(GtkCTree *ctree, GtkCTreeNode *node, gpointer user_data _U_)
|
|||
|
||||
finfo = gtk_ctree_node_get_row_data( ctree, node);
|
||||
g_assert(finfo);
|
||||
g_assert(finfo->tree_type >= 0 && finfo->tree_type < num_tree_types);
|
||||
|
||||
val = &tree_is_expanded[finfo->tree_type];
|
||||
*val = FALSE;
|
||||
|
@ -905,6 +907,7 @@ proto_tree_draw_node(GNode *node, gpointer data)
|
|||
|
||||
if (g_node_n_children(node) > 0) {
|
||||
is_leaf = FALSE;
|
||||
g_assert(fi->tree_type >= 0 && fi->tree_type < num_tree_types);
|
||||
if (tree_is_expanded[fi->tree_type]) {
|
||||
is_expanded = TRUE;
|
||||
}
|
||||
|
|
3
print.c
3
print.c
|
@ -1,7 +1,7 @@
|
|||
/* print.c
|
||||
* Routines for printing packet analysis trees.
|
||||
*
|
||||
* $Id: print.c,v 1.43 2002/03/31 20:56:59 guy Exp $
|
||||
* $Id: print.c,v 1.44 2002/04/01 02:00:50 guy Exp $
|
||||
*
|
||||
* Gilbert Ramirez <gram@alumni.rice.edu>
|
||||
*
|
||||
|
@ -199,6 +199,7 @@ void proto_tree_print_node_text(GNode *node, gpointer data)
|
|||
|
||||
/* If we're printing all levels, or if this level is expanded,
|
||||
recurse into the subtree, if it exists. */
|
||||
g_assert(fi->tree_type >= 0 && fi->tree_type < num_tree_types);
|
||||
if (pdata->print_all_levels || tree_is_expanded[fi->tree_type]) {
|
||||
if (g_node_n_children(node) > 0) {
|
||||
pdata->level++;
|
||||
|
|
Loading…
Reference in New Issue