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 <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2015-12-05 12:40:58 -08:00
parent b3fa4f34f4
commit 4348d4dd34
3 changed files with 10 additions and 9 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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;