Skip to content

Commit

Permalink
filterx-istype: add FilterXRef safety check
Browse files Browse the repository at this point in the history
FilterXRef can mimic the functionality of its referenced value, but only
through virtual methods.

filterx_object_is_type() is usually followed by an implicit type cast,
which is impossible to implement transparently (without the unwrap() call),
so this safety check has been added. This is far from ideal, but doing
downcasts is the original and real problem here.

Signed-off-by: László Várady <[email protected]>
  • Loading branch information
MrAnno committed Oct 12, 2024
1 parent e6d8c3b commit 427be8e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/filterx/filterx-object-istype.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "filterx/filterx-ref.h"

static inline gboolean
filterx_object_is_type(FilterXObject *object, FilterXType *type)
_filterx_object_is_type(FilterXObject *object, FilterXType *type)
{
FilterXType *self_type = object->type;
while (self_type)
Expand All @@ -42,3 +42,14 @@ filterx_object_is_type(FilterXObject *object, FilterXType *type)
}
return FALSE;
}

static inline gboolean
filterx_object_is_type(FilterXObject *object, FilterXType *type)
{
#if SYSLOG_NG_ENABLE_DEBUG
g_assert(!(_filterx_type_is_referenceable(type) && _filterx_object_is_type(object, &FILTERX_TYPE_NAME(ref)))
&& "filterx_ref_unwrap() must be used before comparing to mutable types");
#endif

return _filterx_object_is_type(object, type);
}

0 comments on commit 427be8e

Please sign in to comment.