aboutsummaryrefslogtreecommitdiffstats
path: root/prefs.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2001-11-03 21:37:00 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2001-11-03 21:37:00 +0000
commit445e938ca560fbb79b7ccf4b6471e8cee12cb153 (patch)
tree2ca003cc50aa44ec2a01212a7f1335ae76bc93e2 /prefs.c
parent3b2579dcee9bbb7cd405111e65c4581d14aa7dd2 (diff)
Crash if a dissector tries to create more than one preference with the
same name; if that happens, there's no way to tell to which of them a line in a preferences file, or an option supplied with "-o", refers, so it's clearly a bug in the code. This has happened in the past, and fixing that required some preference renaming *and* code in the preferences-file-reading code to try to preserve the user's settings and not spew warnings when starting Ethereal or Tethereal; let's try to catch it *before* the code gets into the code base. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@4143 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'prefs.c')
-rw-r--r--prefs.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/prefs.c b/prefs.c
index ae81638054..f58c1dce3c 100644
--- a/prefs.c
+++ b/prefs.c
@@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
- * $Id: prefs.c,v 1.68 2001/10/24 07:18:36 guy Exp $
+ * $Id: prefs.c,v 1.69 2001/11/03 21:37:00 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -53,6 +53,7 @@
#include "prefs-int.h"
/* Internal functions */
+static struct preference *find_preference(module_t *, const char *);
static int set_pref(gchar*, gchar*);
static GList *get_string_list(gchar *);
static gchar *put_string_list(GList *);
@@ -224,6 +225,18 @@ register_preference(module_t *module, const char *name, const char *title,
preference->description = description;
preference->ordinal = module->numprefs;
+ /*
+ * Make sure there's not already a preference with that
+ * name. Crash if there is, as that's an error in the
+ * code, and the code has to be fixed not to register
+ * more than one preference with the same name.
+ */
+ g_assert(find_preference(module, name) == NULL);
+
+ /*
+ * There isn't already one with that name, so add the
+ * preference.
+ */
module->prefs = g_list_append(module->prefs, preference);
module->numprefs++;
@@ -244,11 +257,12 @@ preference_match(gconstpointer a, gconstpointer b)
}
static struct preference *
-find_preference(module_t *module, char *name)
+find_preference(module_t *module, const char *name)
{
GList *list_entry;
- list_entry = g_list_find_custom(module->prefs, name, preference_match);
+ list_entry = g_list_find_custom(module->prefs, (gpointer)name,
+ preference_match);
if (list_entry == NULL)
return NULL; /* no such preference */
return (struct preference *) list_entry->data;