From cec9935c33719cb14ff217e5ab1c28830de5e08b Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Thu, 9 Oct 2025 09:22:55 -0600 Subject: [PATCH] testsuites/validation: fix setjmp UB Storing the return value of setjmp to a local variable is undefined behavior. Fixes #5373. --- testsuites/validation/tc-task-restart.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/testsuites/validation/tc-task-restart.c b/testsuites/validation/tc-task-restart.c index 69de846871..c35d36cc3f 100644 --- a/testsuites/validation/tc-task-restart.c +++ b/testsuites/validation/tc-task-restart.c @@ -777,19 +777,15 @@ static void Signal( rtems_signal_set signals ) if ( ctx->interrupt || ctx->nested_request ) { if ( ctx->blocked ) { SetFatalHandler( ResumeThreadDispatch, ctx ); - cpu_self = _Thread_Dispatch_disable(); + (void) _Thread_Dispatch_disable(); - int jumped = setjmp( ctx->thread_dispatch_context ); - - /* cpu_self can be clobbered by setjmp/longjmp, so reload it */ - cpu_self = _Per_CPU_Get(); - - if ( jumped == 0 ) { + if ( setjmp( ctx->thread_dispatch_context ) == 0 ) { Block( ctx ); } else { - _Thread_Dispatch_unnest( cpu_self ); + _Thread_Dispatch_unnest( _Per_CPU_Get() ); } + cpu_self = _Per_CPU_Get(); if ( ctx->interrupt ) { CallWithinISR( Restart, ctx ); } else {