summaryrefslogtreecommitdiff
path: root/regcomp_trie.c
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2023-01-09 22:28:19 +0100
committerYves Orton <demerphq@gmail.com>2023-01-15 13:46:02 +0100
commit3645ca4ee1a59fae1a6d6817c4582968ffd0a731 (patch)
tree5dfc9f0339ae764b273ed711a35835ef15c5f988 /regcomp_trie.c
parent0e946b8626799edfa80f978f41e9abb045579c24 (diff)
downloadperl-3645ca4ee1a59fae1a6d6817c4582968ffd0a731.tar.gz
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.
Diffstat (limited to 'regcomp_trie.c')
-rw-r--r--regcomp_trie.c19
1 files changed, 11 insertions, 8 deletions
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 */