Skip to content

Commit fcf5001

Browse files
committed
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.
1 parent 91a0a58 commit fcf5001

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

regcomp_trie.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,6 +1308,9 @@ Perl_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch,
13081308
#ifdef DEBUGGING
13091309
regnode *optimize = NULL;
13101310
#endif /* DEBUGGING */
1311+
/* make sure we have enough room to inject the TRIE op */
1312+
assert((!trie->jump) || !trie->jump[1] ||
1313+
(trie->jump[1] >= (sizeof(tregnode_TRIE)/sizeof(struct regnode))));
13111314
/*
13121315
This means we convert either the first branch or the first Exact,
13131316
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,
14781481
*/
14791482
if ( !trie->states[trie->startstate].wordnum
14801483
&& trie->bitmap
1481-
&& ( (char *)jumper - (char *)convert) >= (int)sizeof(struct regnode_charclass) )
1484+
&& ( (char *)jumper - (char *)convert) >= (int)sizeof(tregnode_TRIEC) )
14821485
{
14831486
OP( convert ) = TRIEC;
1484-
Copy(trie->bitmap, ((struct regnode_charclass *)convert)->bitmap, ANYOF_BITMAP_SIZE, char);
1487+
Copy(trie->bitmap, ((tregnode_TRIEC *)convert)->bitmap, ANYOF_BITMAP_SIZE, char);
14851488
PerlMemShared_free(trie->bitmap);
14861489
trie->bitmap= NULL;
14871490
} else
@@ -1608,14 +1611,14 @@ Perl_construct_ahocorasick_from_trie(pTHX_ RExC_state_t *pRExC_state, regnode *s
16081611
#endif
16091612

16101613
if ( OP(source) == TRIE ) {
1611-
struct regnode_1 *op = (struct regnode_1 *)
1612-
PerlMemShared_calloc(1, sizeof(struct regnode_1));
1613-
StructCopy(source, op, struct regnode_1);
1614+
tregnode_TRIE *op = (tregnode_TRIE *)
1615+
PerlMemShared_calloc(1, sizeof(tregnode_TRIE));
1616+
StructCopy(source, op, tregnode_TRIE);
16141617
stclass = (regnode *)op;
16151618
} else {
1616-
struct regnode_charclass *op = (struct regnode_charclass *)
1617-
PerlMemShared_calloc(1, sizeof(struct regnode_charclass));
1618-
StructCopy(source, op, struct regnode_charclass);
1619+
tregnode_TRIEC *op = (tregnode_TRIEC *)
1620+
PerlMemShared_calloc(1, sizeof(tregnode_TRIEC));
1621+
StructCopy(source, op, tregnode_TRIEC);
16191622
stclass = (regnode *)op;
16201623
}
16211624
OP(stclass)+=2; /* convert the TRIE type to its AHO-CORASICK equivalent */

0 commit comments

Comments
 (0)