From 522f32f7ef277d1ebe5b41cb764af66d4ca978bb Mon Sep 17 00:00:00 2001 From: wangchengdong Date: Mon, 3 Nov 2025 17:11:16 +0800 Subject: [PATCH] sched/event: Fix uninitialized need_switch flag issue in event_post() The `need_switch` flag was not initialized in `event_post()`. Since it is a local variable, it could contain a random non-zero value, leading to incorrect behavior. In addition, this patch also fixes an issue where the event clearing operation in `event_post()` was not performed correctly. Signed-off-by: Chengdong Wang wangchengdong@lixiang.com --- sched/event/event_post.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sched/event/event_post.c b/sched/event/event_post.c index 03ae633142b..3efc3f7d64d 100644 --- a/sched/event/event_post.c +++ b/sched/event/event_post.c @@ -68,7 +68,7 @@ int nxevent_post(FAR nxevent_t *event, nxevent_mask_t events, dq_queue_t *waitlist; bool waitall; bool postall; - bool need_switch; + bool need_switch = false; if (event == NULL) { @@ -133,11 +133,11 @@ int nxevent_post(FAR nxevent_t *event, nxevent_mask_t events, break; } } + } - if (clear) - { - event->events &= ~clear; - } + if (clear != 0) + { + event->events &= ~clear; } if (need_switch)