From b551bbf747b1b058e6a8568a133373cacbdbe746 Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Wed, 15 Dec 2021 15:51:59 +0100 Subject: [PATCH] sys/ztimer: don't access non-existant timer --- sys/ztimer/core.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/sys/ztimer/core.c b/sys/ztimer/core.c index 01205f1cf2..437573fb67 100644 --- a/sys/ztimer/core.c +++ b/sys/ztimer/core.c @@ -366,20 +366,23 @@ void ztimer_handler(ztimer_clock_t *clock) } #endif - clock->list.offset += clock->list.next->offset; - clock->list.next->offset = 0; + if (clock->list.next) { + clock->list.offset += clock->list.next->offset; + clock->list.next->offset = 0; - ztimer_t *entry = _now_next(clock); - while (entry) { - DEBUG("ztimer_handler(): trigger %p->%p at %" PRIu32 "\n", - (void *)entry, (void *)entry->base.next, clock->ops->now(clock)); - entry->callback(entry->arg); - entry = _now_next(clock); - if (!entry) { - /* See if any more alarms expired during callback processing */ - /* This reduces the number of implicit calls to clock->ops->now() */ - _ztimer_update_head_offset(clock); + ztimer_t *entry = _now_next(clock); + while (entry) { + DEBUG("ztimer_handler(): trigger %p->%p at %" PRIu32 "\n", + (void *)entry, (void *)entry->base.next, clock->ops->now( + clock)); + entry->callback(entry->arg); entry = _now_next(clock); + if (!entry) { + /* See if any more alarms expired during callback processing */ + /* This reduces the number of implicit calls to clock->ops->now() */ + _ztimer_update_head_offset(clock); + entry = _now_next(clock); + } } }