From ce7c79c0a3c5def4d5f8bc32f93dc9e5e443e636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Mayer?= Date: Tue, 18 Sep 2012 19:04:04 +0000 Subject: [PATCH] dissector_add_uint: Legalize formerly improper use of the API when calling it with pattern value of 0 svn path=/trunk/; revision=44978 --- epan/packet.c | 85 ++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/epan/packet.c b/epan/packet.c index 85d7768694..a6f48bf68c 100644 --- a/epan/packet.c +++ b/epan/packet.c @@ -735,56 +735,63 @@ dissector_add_uint_sanity_check(const char *name, guint32 pattern, dissector_han void 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. - */ - 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; - } + * Legalize formerly improper use of the API when calling it with + * a pattern value of 0 + */ + if (pattern) { + dissector_table_t sub_dissectors; + dtbl_entry_t *dtbl_entry; - /* sanity checks */ - g_assert(handle!=NULL); - switch (sub_dissectors->type) { + sub_dissectors = find_dissector_table(name); - 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: - /* - * But you can't do a uint lookup in any other types - * of tables. - */ - g_assert_not_reached(); - } + /* sanity checks */ + 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. + */ + break; + + default: + /* + * But you can't do a uint lookup in any other types + * of tables. + */ + g_assert_not_reached(); + } #if 0 - dissector_add_uint_sanity_check(name, pattern, handle, sub_dissectors); + dissector_add_uint_sanity_check(name, pattern, handle, sub_dissectors); #endif - dtbl_entry = g_malloc(sizeof (dtbl_entry_t)); - dtbl_entry->current = handle; - dtbl_entry->initial = dtbl_entry->current; + dtbl_entry = g_malloc(sizeof (dtbl_entry_t)); + dtbl_entry->current = handle; + dtbl_entry->initial = dtbl_entry->current; - /* do the table insertion */ - g_hash_table_insert( sub_dissectors->hash_table, - GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry); + /* do the table insertion */ + g_hash_table_insert( sub_dissectors->hash_table, + GUINT_TO_POINTER( pattern), (gpointer)dtbl_entry); + + } /* * Now add it to the list of handles that could be used with this