Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filterx: unset(): refuse exprs that have no unset() method #301

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/filterx/expr-unset.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,16 @@ filterx_function_unset_new(FilterXFunctionArgs *args, GError **error)

self->exprs = g_ptr_array_new_full(filterx_function_args_len(args), (GDestroyNotify) filterx_expr_unref);
for (guint64 i = 0; i < filterx_function_args_len(args); i++)
g_ptr_array_add(self->exprs, filterx_function_args_get_expr(args, i));
{
FilterXExpr *expr = filterx_function_args_get_expr(args, i);
if (!filterx_expr_unset_available(expr))
{
g_set_error(error, FILTERX_FUNCTION_ERROR, FILTERX_FUNCTION_ERROR_CTOR_FAIL,
"expected argument %d to be unsettable", (gint) i);
goto error;
}
g_ptr_array_add(self->exprs, expr);
}

if (!filterx_function_args_check(args, error))
goto error;
Expand Down
6 changes: 6 additions & 0 deletions lib/filterx/filterx-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ filterx_expr_unset(FilterXExpr *self)
return FALSE;
}

static inline gboolean
filterx_expr_unset_available(FilterXExpr *self)
{
return self->unset != NULL;
}

void filterx_expr_set_location(FilterXExpr *self, CfgLexer *lexer, CFG_LTYPE *lloc);
void filterx_expr_set_location_with_text(FilterXExpr *self, CfgLexer *lexer, CFG_LTYPE *lloc, const gchar *text);
EVTTAG *filterx_expr_format_location_tag(FilterXExpr *self);
Expand Down
Loading