* [musl] [PATCH] src: regex: Remove unreachable code in tre_copy_ast() in
@ 2025-02-16 17:02 Anton Moryakov
2025-04-14 15:17 ` Szabolcs Nagy
0 siblings, 1 reply; 2+ messages in thread
From: Anton Moryakov @ 2025-02-16 17:02 UTC (permalink / raw)
To: musl; +Cc: Anton Moryakov
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@gmail.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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [musl] [PATCH] src: regex: Remove unreachable code in tre_copy_ast() in
2025-02-16 17:02 [musl] [PATCH] src: regex: Remove unreachable code in tre_copy_ast() in Anton Moryakov
@ 2025-04-14 15:17 ` Szabolcs Nagy
0 siblings, 0 replies; 2+ messages in thread
From: Szabolcs Nagy @ 2025-04-14 15:17 UTC (permalink / raw)
To: Anton Moryakov; +Cc: musl
* Anton Moryakov <ant.v.moryakov@gmail.com> [2025-02-16 20:02:11 +0300]:
> 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@gmail.com>
fwiw, this change looks ok.
it is a cosmetic change only.
>
> ---
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-04-14 15:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-16 17:02 [musl] [PATCH] src: regex: Remove unreachable code in tre_copy_ast() in Anton Moryakov
2025-04-14 15:17 ` Szabolcs Nagy
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).