From 4348d4dd34d0efaa5eb9e42969243a309b7115de Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sat, 5 Dec 2015 12:40:58 -0800 Subject: [PATCH] Type cleanups. dfilter_macro_apply_recurse() returns either NULL or a pointer to freshly-allocated memory, so it doesn't return a const pointer. dfilter_macro_apply() calls dfilter_macro_apply_recurse(), so it doesn't return a const pointer, either. In dfilter_compile(), have separate variables for the filter handed in and the macro-expanded filter, the former being const gchar * and the latter being gchar *. Change-Id: I191549bf0ff6c09c1278a98432a907c93d5e0e74 Reviewed-on: https://code.wireshark.org/review/12446 Reviewed-by: Guy Harris --- epan/dfilter/dfilter-macro.c | 8 ++++---- epan/dfilter/dfilter-macro.h | 2 +- epan/dfilter/dfilter.c | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/epan/dfilter/dfilter-macro.c b/epan/dfilter/dfilter-macro.c index 56f84ee317..a971633dbb 100644 --- a/epan/dfilter/dfilter-macro.c +++ b/epan/dfilter/dfilter-macro.c @@ -160,7 +160,7 @@ static gchar* dfilter_macro_resolve(gchar* name, gchar** args, gchar** error) { } -static const gchar* dfilter_macro_apply_recurse(const gchar* text, guint depth, gchar** error) { +static gchar* dfilter_macro_apply_recurse(const gchar* text, guint depth, gchar** error) { enum { OUTSIDE, STARTING, NAME, ARGS } state = OUTSIDE; GString* out; GString* name = NULL; @@ -322,11 +322,11 @@ finish: FREE_ALL(); if (changed) { - const gchar* resolved = dfilter_macro_apply_recurse(out->str, depth + 1, error); + gchar* resolved = dfilter_macro_apply_recurse(out->str, depth + 1, error); g_string_free(out,TRUE); return resolved; } else { - const gchar* out_str = wmem_strdup(NULL, out->str); + gchar* out_str = wmem_strdup(NULL, out->str); g_string_free(out,TRUE); return out_str; } @@ -343,7 +343,7 @@ on_error: } } -const gchar* dfilter_macro_apply(const gchar* text, gchar** error) { +gchar* dfilter_macro_apply(const gchar* text, gchar** error) { return dfilter_macro_apply_recurse(text, 0, error); } diff --git a/epan/dfilter/dfilter-macro.h b/epan/dfilter/dfilter-macro.h index 89622529ab..9516648de2 100644 --- a/epan/dfilter/dfilter-macro.h +++ b/epan/dfilter/dfilter-macro.h @@ -42,7 +42,7 @@ typedef struct _dfilter_macro_t { } dfilter_macro_t; /* applies all macros to the given text and returns the resulting string or NULL on failure */ -const gchar* dfilter_macro_apply(const gchar* text, gchar** error); +gchar* dfilter_macro_apply(const gchar* text, gchar** error); void dfilter_macro_init(void); diff --git a/epan/dfilter/dfilter.c b/epan/dfilter/dfilter.c index 030a0efcba..a843bbe936 100644 --- a/epan/dfilter/dfilter.c +++ b/epan/dfilter/dfilter.c @@ -210,6 +210,7 @@ dfwork_free(dfwork_t *dfw) gboolean dfilter_compile(const gchar *text, dfilter_t **dfp, gchar **err_msg) { + gchar *expanded_text; int token; dfilter_t *dfilter; dfwork_t *dfw; @@ -228,7 +229,7 @@ dfilter_compile(const gchar *text, dfilter_t **dfp, gchar **err_msg) return FALSE; } - if ( !( text = dfilter_macro_apply(text, err_msg) ) ) { + if ( !( expanded_text = dfilter_macro_apply(text, err_msg) ) ) { return FALSE; } @@ -240,7 +241,7 @@ dfilter_compile(const gchar *text, dfilter_t **dfp, gchar **err_msg) */ global_dfw = dfw; - df_scanner_text(text); + df_scanner_text(expanded_text); deprecated = g_ptr_array_new(); @@ -359,7 +360,7 @@ dfilter_compile(const gchar *text, dfilter_t **dfp, gchar **err_msg) /* SUCCESS */ global_dfw = NULL; dfwork_free(dfw); - wmem_free(NULL, (char*)text); + wmem_free(NULL, expanded_text); return TRUE; FAILURE: @@ -384,7 +385,7 @@ FAILURE: * case for any error. */ if (*err_msg == NULL) - *err_msg = g_strdup_printf("Unable to parse filter string \"%s\".", text); + *err_msg = g_strdup_printf("Unable to parse filter string \"%s\".", expanded_text); } *dfp = NULL; return FALSE;