dfilter: Cleanup handling of null/empty expressions

This commit is contained in:
João Valverde 2023-04-21 00:26:53 +01:00
parent 43117dd40f
commit 435a2186ab
2 changed files with 12 additions and 15 deletions

View file

@ -450,23 +450,20 @@ dfilter_compile_full(const gchar *text, dfilter_t **dfp,
*dfp = NULL; *dfp = NULL;
if (text == NULL) { if (text == NULL) {
ws_debug("%s() called from %s() with null filter", ws_warning("Called from %s() with null filter", caller);
__func__, caller);
/* XXX This BUG happens often. Some callers are ignoring these errors. */
if (err_ptr) if (err_ptr)
*err_ptr = df_error_new_msg("BUG: NULL text pointer passed to dfilter_compile"); *err_ptr = df_error_new_msg("BUG: NULL text pointer");
return FALSE; return FALSE;
} }
else if (*text == '\0') { if (*text == '\0') {
/* An empty filter is considered a valid input. */ ws_warning("Called from %s() with empty filter", caller);
ws_debug("%s() called from %s() with empty filter", if (err_ptr)
__func__, caller); *err_ptr = df_error_new_msg("Filter expression is empty");
} return FALSE;
else {
ws_debug("%s() called from %s(), compiling filter: %s",
__func__, caller, text);
} }
ws_debug("Called from %s() with filter: %s", caller, text);
dfw = dfwork_new(flags); dfw = dfwork_new(flags);
if (flags & DF_EXPAND_MACROS) { if (flags & DF_EXPAND_MACROS) {

View file

@ -554,7 +554,7 @@ register_tap_listener(const char *tapname, void *tapdata, const char *fstring,
tl->needs_redraw=TRUE; tl->needs_redraw=TRUE;
tl->failed=FALSE; tl->failed=FALSE;
tl->flags=flags; tl->flags=flags;
if(fstring){ if(fstring && *fstring){
if(!dfilter_compile(fstring, &code, &df_err)){ if(!dfilter_compile(fstring, &code, &df_err)){
error_string = g_string_new(""); error_string = g_string_new("");
g_string_printf(error_string, g_string_printf(error_string,
@ -564,9 +564,9 @@ register_tap_listener(const char *tapname, void *tapdata, const char *fstring,
free_tap_listener(tl); free_tap_listener(tl);
return error_string; return error_string;
} }
tl->fstring=g_strdup(fstring);
tl->code=code;
} }
tl->fstring=g_strdup(fstring);
tl->code=code;
tl->tap_id=tap_id; tl->tap_id=tap_id;
tl->tapdata=tapdata; tl->tapdata=tapdata;