regex: clean up position accounting for literal nodes
authorSzabolcs Nagy <nsz@port70.net>
Sat, 18 Apr 2015 14:31:07 +0000 (14:31 +0000)
committerRich Felker <dalias@aerifal.cx>
Sun, 31 Jan 2016 01:51:58 +0000 (20:51 -0500)
This should not change the meaning of the code, just make the intent
clearer: advancing position is tied to adding a new literal.

src/regex/regcomp.c

index 330de46759730b55b90d9080fb7798d37ae5db86..ac207c8991f213e5de5a0e368bc315c07ea07ce0 100644 (file)
@@ -834,22 +834,20 @@ static reg_errcode_t parse_atom(tre_parse_ctx_t *ctx, const char *s)
                                        return REG_EBRACE;
                                s++;
                        }
-                       node = tre_ast_new_literal(ctx->mem, v, v, ctx->position);
-                       ctx->position++;
+                       node = tre_ast_new_literal(ctx->mem, v, v, ctx->position++);
                        s--;
                        break;
                default:
                        if (!ere && (unsigned)*s-'1' < 9) {
                                /* back reference */
                                int val = *s - '0';
-                               node = tre_ast_new_literal(ctx->mem, BACKREF, val, ctx->position);
+                               node = tre_ast_new_literal(ctx->mem, BACKREF, val, ctx->position++);
                                ctx->max_backref = MAX(val, ctx->max_backref);
                        } else {
                                /* extension: accept unknown escaped char
                                   as a literal */
                                goto parse_literal;
                        }
-                       ctx->position++;
                }
                s++;
                break;