From 55356470f9fe0b60bd9e0db1e90dbca6b4e7db63 Mon Sep 17 00:00:00 2001 From: dimitri staessens Date: Fri, 5 Aug 2016 15:04:50 +0200 Subject: lib:shm_du_map: Fix wrong element access The check whether the du map is empty should be first. --- src/lib/shm_du_map.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/lib/shm_du_map.c b/src/lib/shm_du_map.c index 6527e035..8d197232 100644 --- a/src/lib/shm_du_map.c +++ b/src/lib/shm_du_map.c @@ -91,13 +91,14 @@ static void garbage_collect(struct shm_du_map * dum) { #ifdef SHM_DU_MAP_MULTI_BLOCK struct shm_du_buff * sdb; - while ((sdb = get_tail_ptr(dum))->dst_api == -1 && - !shm_map_empty(dum)) + while (!shm_map_empty(dum) && + (sdb = get_tail_ptr(dum))->dst_api == -1) + *dum->ptr_tail = (*dum->ptr_tail + sdb->blocks) & (SHM_BUFFER_SIZE - 1); #else - while (get_tail_ptr(dum)->dst_api == -1 && - !shm_map_empty(dum)) + while (!shm_map_empty(dum) && + get_tail_ptr(dum)->dst_api == -1) *dum->ptr_tail = (*dum->ptr_tail + 1) & (SHM_BUFFER_SIZE - 1); -- cgit v1.2.3