From 3645ca4ee1a59fae1a6d6817c4582968ffd0a731 Mon Sep 17 00:00:00 2001 From: Yves Orton Date: Mon, 9 Jan 2023 22:28:19 +0100 Subject: regcomp_trie.c - use the indirect types so we are safe to changes We shouldnt assume that a TRIEC is a regcomp_charclass. We have a per opcode type exactly for this type of use, so lets use it. --- regcomp_trie.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'regcomp_trie.c') diff --git a/regcomp_trie.c b/regcomp_trie.c index 65963cacf2..cf692d0821 100644 --- a/regcomp_trie.c +++ b/regcomp_trie.c @@ -1308,6 +1308,9 @@ Perl_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch, #ifdef DEBUGGING regnode *optimize = NULL; #endif /* DEBUGGING */ + /* make sure we have enough room to inject the TRIE op */ + assert((!trie->jump) || !trie->jump[1] || + (trie->jump[1] >= (sizeof(tregnode_TRIE)/sizeof(struct regnode)))); /* This means we convert either the first branch or the first Exact, depending on whether the thing following (in 'last') is a branch @@ -1478,10 +1481,10 @@ Perl_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch, */ if ( !trie->states[trie->startstate].wordnum && trie->bitmap - && ( (char *)jumper - (char *)convert) >= (int)sizeof(struct regnode_charclass) ) + && ( (char *)jumper - (char *)convert) >= (int)sizeof(tregnode_TRIEC) ) { OP( convert ) = TRIEC; - Copy(trie->bitmap, ((struct regnode_charclass *)convert)->bitmap, ANYOF_BITMAP_SIZE, char); + Copy(trie->bitmap, ((tregnode_TRIEC *)convert)->bitmap, ANYOF_BITMAP_SIZE, char); PerlMemShared_free(trie->bitmap); trie->bitmap= NULL; } else @@ -1608,14 +1611,14 @@ Perl_construct_ahocorasick_from_trie(pTHX_ RExC_state_t *pRExC_state, regnode *s #endif if ( OP(source) == TRIE ) { - struct regnode_1 *op = (struct regnode_1 *) - PerlMemShared_calloc(1, sizeof(struct regnode_1)); - StructCopy(source, op, struct regnode_1); + tregnode_TRIE *op = (tregnode_TRIE *) + PerlMemShared_calloc(1, sizeof(tregnode_TRIE)); + StructCopy(source, op, tregnode_TRIE); stclass = (regnode *)op; } else { - struct regnode_charclass *op = (struct regnode_charclass *) - PerlMemShared_calloc(1, sizeof(struct regnode_charclass)); - StructCopy(source, op, struct regnode_charclass); + tregnode_TRIEC *op = (tregnode_TRIEC *) + PerlMemShared_calloc(1, sizeof(tregnode_TRIEC)); + StructCopy(source, op, tregnode_TRIEC); stclass = (regnode *)op; } OP(stclass)+=2; /* convert the TRIE type to its AHO-CORASICK equivalent */ -- cgit v1.2.1