dissector_add_uint:

Legalize formerly improper use of the API when calling it with
   pattern value of 0

svn path=/trunk/; revision=44978
This commit is contained in:
Jörg Mayer 2012-09-18 19:04:04 +00:00
parent 183cbe9af1
commit ce7c79c0a3
1 changed files with 46 additions and 39 deletions

View File

@ -735,56 +735,63 @@ dissector_add_uint_sanity_check(const char *name, guint32 pattern, dissector_han
void void
dissector_add_uint(const char *name, const guint32 pattern, dissector_handle_t handle) dissector_add_uint(const char *name, const guint32 pattern, dissector_handle_t handle)
{ {
dissector_table_t sub_dissectors;
dtbl_entry_t *dtbl_entry;
sub_dissectors = find_dissector_table(name);
/* /*
* Make sure the dissector table exists. * Legalize formerly improper use of the API when calling it with
*/ * a pattern value of 0
if (sub_dissectors == NULL) { */
fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n", if (pattern) {
name); dissector_table_t sub_dissectors;
fprintf(stderr, "Protocol being registered is \"%s\"\n", dtbl_entry_t *dtbl_entry;
proto_get_protocol_long_name(handle->protocol));
if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
abort();
return;
}
/* sanity checks */ sub_dissectors = find_dissector_table(name);
g_assert(handle!=NULL);
switch (sub_dissectors->type) {
case FT_UINT8:
case FT_UINT16:
case FT_UINT24:
case FT_UINT32:
/* /*
* You can do a uint lookup in these tables. * Make sure the dissector table exists.
*/ */
break; if (sub_dissectors == NULL) {
fprintf(stderr, "OOPS: dissector table \"%s\" doesn't exist\n",
name);
fprintf(stderr, "Protocol being registered is \"%s\"\n",
proto_get_protocol_long_name(handle->protocol));
if (getenv("WIRESHARK_ABORT_ON_DISSECTOR_BUG") != NULL)
abort();
return;
}
default: /* sanity checks */
/* g_assert(handle!=NULL);
* But you can't do a uint lookup in any other types switch (sub_dissectors->type) {
* of tables.
*/ case FT_UINT8:
g_assert_not_reached(); case FT_UINT16:
} case FT_UINT24:
case FT_UINT32:
/*
* You can do a uint lookup in these tables.
*/
break;
default:
/*
* But you can't do a uint lookup in any other types
* of tables.
*/
g_assert_not_reached();
}
#if 0 #if 0
dissector_add_uint_sanity_check(name, pattern, handle, sub_dissectors); dissector_add_uint_sanity_check(name, pattern, handle, sub_dissectors);
#endif #endif
dtbl_entry = g_malloc(sizeof (dtbl_entry_t)); dtbl_entry = g_malloc(sizeof (dtbl_entry_t));
dtbl_entry->current = handle; dtbl_entry->current = handle;
dtbl_entry->initial = dtbl_entry->current; dtbl_entry->initial = dtbl_entry->current;
/* do the table insertion */ /* do the table insertion */
g_hash_table_insert( sub_dissectors->hash_table, g_hash_table_insert( sub_dissectors->hash_table,
GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry); GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry);
}
/* /*
* Now add it to the list of handles that could be used with this * Now add it to the list of handles that could be used with this