Skip to content

Commit

Permalink
Improve error checks in tre_parse().
Browse files Browse the repository at this point in the history
* Remove redundant status check at the top of the loop.  It's already part of the loop condition.
* Check status immediately after the loop terminates, so if we hit the stack limit, we correctly return REG_ESPACE, not REG_EPAREN.
  • Loading branch information
dag-erling committed Mar 20, 2024
1 parent 905c83d commit a68835d
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/tre-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -958,8 +958,6 @@ tre_parse(tre_parse_ctx_t *ctx)
call stack, and efficiency (both in lines of code and speed). */
while (tre_stack_num_objects(stack) > bottom && status == REG_OK)
{
if (status != REG_OK)
break;
symbol = tre_stack_pop_int(stack);
switch (symbol)
{
Expand Down Expand Up @@ -1728,14 +1726,15 @@ tre_parse(tre_parse_ctx_t *ctx)
}
}

if (status != REG_OK)
return status;

/* Check for missing closing parentheses. */
if (depth > 0)
return REG_EPAREN;

if (status == REG_OK)
ctx->result = result;

return status;
ctx->result = result;
return REG_OK;
}

/* EOF */

0 comments on commit a68835d

Please sign in to comment.