From: Alan T. DeKok Date: Mon, 3 Aug 2026 13:37:27 +0000 (-0400) Subject: bypass walk up the stack in NDEBUG mode X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ddccc184b19f2f4f67284d9fa904a67277da783;p=thirdparty%2Ffreeradius-server.git bypass walk up the stack in NDEBUG mode when finding a frame by op flag. --- diff --git a/src/lib/unlang/unlang_priv.h b/src/lib/unlang/unlang_priv.h index f758cec4385..e04827c3f0c 100644 --- a/src/lib/unlang/unlang_priv.h +++ b/src/lib/unlang/unlang_priv.h @@ -558,18 +558,19 @@ static inline unsigned int unlang_frame_by_flag(unlang_stack_t *stack, unlang_fr */ static inline unsigned int unlang_frame_by_op_flag(unlang_stack_t *stack, unlang_op_flag_t flag) { - unsigned int i; + unlang_stack_frame_t *frame; + #ifndef NDEBUG unlang_stack_frame_t *current = &stack->frame[stack->depth]; -#endif - + unsigned int i; for (i = stack->depth; i > 0; i--) { - unlang_stack_frame_t *frame = &stack->frame[i]; + frame = &stack->frame[i]; if (unlang_ops[frame->instruction->type].flag & flag) { switch (flag) { default: + fr_assert(0); break; case UNLANG_OP_FLAG_BREAK_POINT: @@ -596,6 +597,27 @@ static inline unsigned int unlang_frame_by_op_flag(unlang_stack_t *stack, unlang */ if (is_top_frame(frame)) return 0; } +#else + frame = &stack->frame[stack->depth]; + + /* + * No asserts in NDEBUG mode. Just return the frame, and stop looping up the stack. + */ + switch (flag) { + default: + break; + + case UNLANG_OP_FLAG_BREAK_POINT: + return frame->prev.frame_break; + + case UNLANG_OP_FLAG_RETURN_POINT: + return frame->prev.frame_return; + + case UNLANG_OP_FLAG_CONTINUE_POINT: + return frame->prev.frame_continue; + } +#endif + return 0; }