Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20250216170211.705292-1-ant.v.moryakov@gmail.com>
Date: Sun, 16 Feb 2025 20:02:11 +0300
From: Anton Moryakov <ant.v.moryakov@...il.com>
To: musl@...ts.openwall.com
Cc: Anton Moryakov <ant.v.moryakov@...il.com>
Subject: [PATCH] src: regex: Remove unreachable code in tre_copy_ast() in

Static analyzer reported:
UNREACHABLE_CODE This statement in the source code might be unreachable during program execution.

Corrections explained:
The check if (status != REG_OK) break; inside the while loop was unnecessary
because the loop condition while (status == REG_OK && tre_stack_num_objects(stack) > bottom)
already ensures that status is REG_OK. 

Since status != REG_OK can never be true within the loop, the break statement
was unreachable and has been removed.

This change does not alter the program's behavior but improves code clarity.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@...il.com>

---
 src/regex/regcomp.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/src/regex/regcomp.c b/src/regex/regcomp.c
index fb24556e..8c637bdc 100644
--- a/src/regex/regcomp.c
+++ b/src/regex/regcomp.c
@@ -1701,8 +1701,6 @@ tre_copy_ast(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *ast,
   while (status == REG_OK && tre_stack_num_objects(stack) > bottom)
     {
       tre_ast_node_t *node;
-      if (status != REG_OK)
-	break;
 
       symbol = (tre_copyast_symbol_t)tre_stack_pop_int(stack);
       switch (symbol)
@@ -1849,9 +1847,6 @@ tre_expand_ast(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *ast,
       tre_ast_node_t *node;
       tre_expand_ast_symbol_t symbol;
 
-      if (status != REG_OK)
-	break;
-
       symbol = (tre_expand_ast_symbol_t)tre_stack_pop_int(stack);
       node = tre_stack_pop_voidptr(stack);
       switch (symbol)
-- 
2.30.2

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.