From 7c3fd2a6903ced8adb89659a4105d22031442edf Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Mon, 16 Feb 2015 03:13:25 +0000 Subject: Revert "Revert "Fix duplicate Display Filter Macro check"" This reverts commit 876c322df8b6a944cb4358c313c4fc46afe99719. Wrong branch. It builds in master; it does *not* build in 1.12 or 1.10. Change-Id: I3a2409d5a37f08965d6caac64dc97a48a1c5d1b8 Reviewed-on: https://code.wireshark.org/review/7152 Reviewed-by: Guy Harris --- epan/dfilter/dfilter-macro.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'epan/dfilter') diff --git a/epan/dfilter/dfilter-macro.c b/epan/dfilter/dfilter-macro.c index 7f805859ad..234e2cea00 100644 --- a/epan/dfilter/dfilter-macro.c +++ b/epan/dfilter/dfilter-macro.c @@ -403,7 +403,7 @@ const gchar* dfilter_macro_apply(const gchar* text, gchar** error) { return dfilter_macro_apply_recurse(text, 0, error); } -static void macro_update(void* mp, gchar** error) { +static void macro_update(void* mp, gchar** error _U_) { dfilter_macro_t* m = (dfilter_macro_t*)mp; GPtrArray* parts; GArray* args_pos; @@ -411,22 +411,9 @@ static void macro_update(void* mp, gchar** error) { gchar* w; gchar* part; int argc = 0; - guint i; DUMP_MACRO(m); - *error = NULL; - - for (i = 0; i < num_macros; i++) { - if (m == &(macros[i])) continue; - - if ( g_str_equal(m->name,macros[i].name) ) { - *error = g_strdup_printf("macro '%s' exists already", m->name); - m->usable = FALSE; - return; - } - } - /* Invalidate the display filter in case it's in use */ if (dfilter_macro_uat && dfilter_macro_uat->post_update_cb) dfilter_macro_uat->post_update_cb(); @@ -591,7 +578,9 @@ static void* macro_copy(void* dest, const void* orig, size_t len _U_) { return d; } -static gboolean macro_name_chk(void* r _U_, const char* in_name, guint name_len, const void* u1 _U_, const void* u2 _U_, char** error) { +static gboolean macro_name_chk(void *mp, const char *in_name, guint name_len, + const void *u1 _U_, const void *u2 _U_, char **error) { + dfilter_macro_t* m = (dfilter_macro_t*)mp; guint i; if (name_len == 0) { @@ -606,6 +595,22 @@ static gboolean macro_name_chk(void* r _U_, const char* in_name, guint name_len, } } + /* When loading (!m->name) or when adding/changing the an item with a + * different name, check for uniqueness. NOTE: if a duplicate already + * exists (because the user manually edited the file), then this will + * not trigger a warning. */ + if (!m->name || !g_str_equal(m->name, in_name)) { + for (i = 0; i < num_macros; i++) { + /* This a string field which is always NUL-terminated, + * so no need to check name_len. */ + if (g_str_equal(in_name, macros[i].name)) { + *error = g_strdup_printf("macro '%s' already exists", + in_name); + return FALSE; + } + } + } + return TRUE; } -- cgit v1.2.1