Skip to content

Commit

Permalink
Fix iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
sashacmc committed Jan 16, 2025
1 parent b84e49c commit 7afad46
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/net/matching.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,16 @@ _z_matching_listener_t _z_matching_listener_declare(_z_session_rc_t *zn, const _

z_result_t _z_matching_listener_entity_undeclare(_z_session_t *zn, _z_zint_t entity_id) {
_z_matching_listener_intmap_iterator_t iter = _z_matching_listener_intmap_iterator_make(&zn->_matching_listeners);
while (_z_matching_listener_intmap_iterator_next(&iter)) {
bool has_next = _z_matching_listener_intmap_iterator_next(&iter);
while (has_next) {
size_t key = _z_matching_listener_intmap_iterator_key(&iter);
_z_matching_listener_state_t *listener = _z_matching_listener_intmap_iterator_value(&iter);
has_next = _z_matching_listener_intmap_iterator_next(&iter);
if (listener->entity_id == entity_id) {
_Z_DEBUG("_z_matching_listener_entity_undeclare: entity=%i, listener=%i", (int)entity_id, (int)key);
_z_matching_listener_intmap_remove(&zn->_matching_listeners, key);
_z_remove_interest(zn, listener->interest_id);
_z_matching_listener_intmap_remove(&zn->_matching_listeners, key);
}
_z_str_intmap_iterator_next(&iter);
}
return _Z_RES_OK;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/z_collections_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,13 @@ void int_map_iterator_deletion_test(void) {
_z_str_intmap_insert(&map, 40, _z_str_clone("D"));

_z_str_intmap_iterator_t iter = _z_str_intmap_iterator_make(&map);
_z_str_intmap_iterator_next(&iter);
for (size_t s = 4; s != 0; s--) {
assert(s == _z_str_intmap_len(&map));
_z_str_intmap_iterator_next(&iter);
size_t key = _z_str_intmap_iterator_key(&iter);
assert(strlen(_z_str_intmap_iterator_value(&iter)) == 1);
_z_str_intmap_remove(&map, key);
_z_str_intmap_iterator_next(&iter);
}
_z_str_intmap_clear(&map);
}
Expand Down

0 comments on commit 7afad46

Please sign in to comment.