From 5f5a934bca72f352f64bc5138c58cbc3dbea8323 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mo=C5=84?= Date: Tue, 27 Aug 2019 17:49:53 +0200 Subject: Use g_hash_table_replace() when key depends on data Using g_hash_table_insert() in cases where the key is contained within value is error prone. Use g_hash_table_replace() to eliminate the risk of ending up with incoherent hash table state. Change-Id: I595457476a2682e927d2c56b2692404aef4dc43a Reviewed-on: https://code.wireshark.org/review/34385 Reviewed-by: Michael Mann Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/stats_tree.c | 2 +- wsutil/plugins.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/epan/stats_tree.c b/epan/stats_tree.c index 10fdc10234..13c9738b32 100644 --- a/epan/stats_tree.c +++ b/epan/stats_tree.c @@ -521,7 +521,7 @@ new_stat_node(stats_tree *st, const gchar *name, int parent_id, stat_node_dataty } if(node->parent->hash) { - g_hash_table_insert(node->parent->hash,node->name,node); + g_hash_table_replace(node->parent->hash,node->name,node); } if (st->cfg->setup_node_pr) { diff --git a/wsutil/plugins.c b/wsutil/plugins.c index 1293ce3672..f4fa859b48 100644 --- a/wsutil/plugins.c +++ b/wsutil/plugins.c @@ -203,7 +203,7 @@ DIAG_ON_PEDANTIC new_plug->type_name = type_to_name(type); /* Add it to the list of plugins. */ - g_hash_table_insert(plugins_module, new_plug->name, new_plug); + g_hash_table_replace(plugins_module, new_plug->name, new_plug); } ws_dir_close(dir); g_free(plugin_folder); -- cgit v1.2.3