diff options
author | Evan Huus <eapache@gmail.com> | 2013-06-17 22:51:50 +0000 |
---|---|---|
committer | Evan Huus <eapache@gmail.com> | 2013-06-17 22:51:50 +0000 |
commit | 5c027c2590a09e5e14122261e6551dd980bfc263 (patch) | |
tree | ccef19b1d7ba636857ddc190edd518175ad7cd93 | |
parent | eba26b89a4e828cbbd25cc86545ee6799e5dc911 (diff) |
Extract some common code for array lookups, and replace some DISSECTOR
assertions with regular glib assertions - there's no guarantee that wmem code
will always be run from within a dissector.
svn path=/trunk/; revision=49993
-rw-r--r-- | epan/wmem/wmem_tree.c | 60 |
1 files changed, 18 insertions, 42 deletions
diff --git a/epan/wmem/wmem_tree.c b/epan/wmem/wmem_tree.c index 497801b21e..d680953875 100644 --- a/epan/wmem/wmem_tree.c +++ b/epan/wmem/wmem_tree.c @@ -546,7 +546,7 @@ wmem_tree_insert32_array(wmem_tree_t *tree, wmem_tree_key_t *key, void *data) for (cur_key = key; cur_key->length > 0; cur_key++) { if(cur_key->length > 100) { - /* XXX FIXME DISSECTOR_ASSERT_NOT_REACHED(); */ + g_assert_not_reached(); } for (i = 0; i < cur_key->length; i++) { @@ -564,22 +564,23 @@ wmem_tree_insert32_array(wmem_tree_t *tree, wmem_tree_key_t *key, void *data) if (!insert_tree) { /* We didn't get a valid key. Should we return NULL instead? */ - /* XXX FIXME DISSECTOR_ASSERT_NOT_REACHED(); */ + g_assert_not_reached(); } wmem_tree_insert32(insert_tree, insert_key32, data); } -void * -wmem_tree_lookup32_array(wmem_tree_t *tree, wmem_tree_key_t *key) +static void * +wmem_tree_lookup32_array_helper(wmem_tree_t *tree, wmem_tree_key_t *key, + void*(*helper)(wmem_tree_t*, guint32)) { wmem_tree_t *lookup_tree = NULL; wmem_tree_key_t *cur_key; guint32 i, lookup_key32 = 0; for (cur_key = key; cur_key->length > 0; cur_key++) { - if(cur_key->length > 100) { - /* XXX FIXME DISSECTOR_ASSERT_NOT_REACHED(); */ + if (cur_key->length > 100) { + g_assert_not_reached(); } for (i = 0; i < cur_key->length; i++) { @@ -587,7 +588,7 @@ wmem_tree_lookup32_array(wmem_tree_t *tree, wmem_tree_key_t *key) if (!lookup_tree) { lookup_tree = tree; } else { - lookup_tree = (wmem_tree_t *)wmem_tree_lookup32(lookup_tree, + lookup_tree = (wmem_tree_t *)(*helper)(lookup_tree, lookup_key32); if (!lookup_tree) { return NULL; @@ -597,48 +598,23 @@ wmem_tree_lookup32_array(wmem_tree_t *tree, wmem_tree_key_t *key) } } - if(!lookup_tree) { - /* We didn't get a valid key. Should we return NULL instead? */ - /* XXX FIXME DISSECTOR_ASSERT_NOT_REACHED(); */ + if (!lookup_tree) { + g_assert_not_reached(); } - return wmem_tree_lookup32(lookup_tree, lookup_key32); + return (*helper)(lookup_tree, lookup_key32); } void * -wmem_tree_lookup32_array_le(wmem_tree_t *tree, wmem_tree_key_t *key) +wmem_tree_lookup32_array(wmem_tree_t *tree, wmem_tree_key_t *key) { - wmem_tree_t *lookup_tree = NULL; - wmem_tree_key_t *cur_key; - guint32 i, lookup_key32 = 0; - - for (cur_key = key; cur_key->length > 0; cur_key++) { - if(cur_key->length > 100) { - /* XXX FIXME DISSECTOR_ASSERT_NOT_REACHED(); */ - } - - for (i = 0; i < cur_key->length; i++) { - /* Lookup using the previous key32 */ - if (!lookup_tree) { - lookup_tree = tree; - } else { - lookup_tree = (wmem_tree_t *)wmem_tree_lookup32_le(lookup_tree, - lookup_key32); - if (!lookup_tree) { - return NULL; - } - } - lookup_key32 = cur_key->key[i]; - } - } - - if(!lookup_tree) { - /* We didn't get a valid key. Should we return NULL instead? */ - /* XXX FIXME DISSECTOR_ASSERT_NOT_REACHED(); */ - } - - return wmem_tree_lookup32_le(lookup_tree, lookup_key32); + return wmem_tree_lookup32_array_helper(tree, key, wmem_tree_lookup32); +} +void * +wmem_tree_lookup32_array_le(wmem_tree_t *tree, wmem_tree_key_t *key) +{ + return wmem_tree_lookup32_array_helper(tree, key, wmem_tree_lookup32_le); } static gboolean |