Skip to content

Commit

Permalink
lib/filterx: fix filterx_scope_foreach_variable
Browse files Browse the repository at this point in the history
The newly extracted _validate_variable takes care of only accessing/modifying
valid variables.

Signed-off-by: Szilard Parrag <szilard.parrag@axoflow.com>
  • Loading branch information
OverOrion committed Oct 31, 2024
1 parent 551e7d9 commit b425b31
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/filterx/filterx-scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,25 @@ filterx_scope_is_dirty(FilterXScope *self)
return self->dirty;
}

static gboolean
_validate_variable(FilterXScope *self, FilterXVariable *variable)
{
if (filterx_variable_is_floating(variable) &&
!filterx_variable_is_declared(variable) &&
!filterx_variable_is_same_generation(variable, self->generation))
return FALSE;
if (!filterx_variable_is_floating(variable) && variable->generation == 0 && self->syncable)
return FALSE;
return TRUE;
}

FilterXVariable *
filterx_scope_lookup_variable(FilterXScope *self, FilterXVariableHandle handle)
{
FilterXVariable *v;

if (_lookup_variable(self, handle, &v))
{
if (filterx_variable_handle_is_floating(handle) &&
!filterx_variable_is_declared(v) &&
!filterx_variable_is_same_generation(v, self->generation))
return NULL;
if (!filterx_variable_handle_is_floating(handle) && v->generation == 0 && self->syncable)
return NULL;
return v;
}
if (_lookup_variable(self, handle, &v) && filterx_scope_validate_variable(self, v))
return v;
return NULL;
}

Expand Down Expand Up @@ -185,9 +189,7 @@ filterx_scope_foreach_variable(FilterXScope *self, FilterXScopeForeachFunc func,
if (!variable->value)
continue;

if (filterx_variable_is_floating(variable) &&
!filterx_variable_is_declared(variable) &&
!filterx_variable_is_same_generation(variable, self->generation))
if (!_validate_variable(self, variable))
continue;

if (!func(variable, user_data))
Expand Down

0 comments on commit b425b31

Please sign in to comment.