Skip to content

Commit 944e05e

Browse files
committed
Fix Perl #126206: handle NOTHING regops and EXACTFU_SS regops in make_trie() properly
... and avoid dereffing non-EXACT nodes unnecessarily at the same time. This fixes https://rt.perl.org/Ticket/Display.html?id=126206
1 parent d95e4a0 commit 944e05e

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

regcomp.c

+25-27
Original file line numberDiff line numberDiff line change
@@ -2505,8 +2505,8 @@ S_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch,
25052505

25062506
for ( cur = first ; cur < last ; cur = regnext( cur ) ) {
25072507
regnode *noper = NEXTOPER( cur );
2508-
const U8 *uc = (U8*)STRING( noper );
2509-
const U8 *e = uc + STR_LEN( noper );
2508+
const U8 *uc;
2509+
const U8 *e;
25102510
int foldlen = 0;
25112511
U32 wordlen = 0; /* required init */
25122512
STRLEN minchars = 0;
@@ -2516,17 +2516,19 @@ S_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch,
25162516

25172517
if (OP(noper) == NOTHING) {
25182518
regnode *noper_next= regnext(noper);
2519-
if (noper_next != tail && OP(noper_next) == flags) {
2520-
noper = noper_next;
2521-
uc= (U8*)STRING(noper);
2522-
e= uc + STR_LEN(noper);
2523-
trie->minlen= STR_LEN(noper);
2524-
} else {
2525-
trie->minlen= 0;
2526-
continue;
2527-
}
2519+
if (noper_next < tail)
2520+
noper= noper_next;
2521+
}
2522+
2523+
if ( noper < tail && ( OP(noper) == flags || ( flags == EXACTFU && OP(noper) == EXACTFU_SS ) ) ) {
2524+
uc= (U8*)STRING(noper);
2525+
e= uc + STR_LEN(noper);
2526+
} else {
2527+
trie->minlen= 0;
2528+
continue;
25282529
}
25292530

2531+
25302532
if ( set_bit ) { /* bitmap only alloced when !(UTF&&Folding) */
25312533
TRIE_BITMAP_SET(trie,*uc); /* store the raw first byte
25322534
regardless of encoding */
@@ -2732,22 +2734,20 @@ S_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch,
27322734
for ( cur = first ; cur < last ; cur = regnext( cur ) ) {
27332735

27342736
regnode *noper = NEXTOPER( cur );
2735-
U8 *uc = (U8*)STRING( noper );
2736-
const U8 *e = uc + STR_LEN( noper );
27372737
U32 state = 1; /* required init */
27382738
U16 charid = 0; /* sanity init */
27392739
U32 wordlen = 0; /* required init */
27402740

27412741
if (OP(noper) == NOTHING) {
27422742
regnode *noper_next= regnext(noper);
2743-
if (noper_next != tail && OP(noper_next) == flags) {
2744-
noper = noper_next;
2745-
uc= (U8*)STRING(noper);
2746-
e= uc + STR_LEN(noper);
2747-
}
2743+
if (noper_next < tail)
2744+
noper= noper_next;
27482745
}
27492746

2750-
if (OP(noper) != NOTHING) {
2747+
if ( noper < tail && ( OP(noper) == flags || ( flags == EXACTFU && OP(noper) == EXACTFU_SS ) ) ) {
2748+
const U8 *uc= (U8*)STRING(noper);
2749+
const U8 *e= uc + STR_LEN(noper);
2750+
27512751
for ( ; uc < e ; uc += len ) {
27522752

27532753
TRIE_READ_CHAR;
@@ -2951,8 +2951,6 @@ S_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch,
29512951
for ( cur = first ; cur < last ; cur = regnext( cur ) ) {
29522952

29532953
regnode *noper = NEXTOPER( cur );
2954-
const U8 *uc = (U8*)STRING( noper );
2955-
const U8 *e = uc + STR_LEN( noper );
29562954

29572955
U32 state = 1; /* required init */
29582956

@@ -2963,14 +2961,14 @@ S_make_trie(pTHX_ RExC_state_t *pRExC_state, regnode *startbranch,
29632961

29642962
if (OP(noper) == NOTHING) {
29652963
regnode *noper_next= regnext(noper);
2966-
if (noper_next != tail && OP(noper_next) == flags) {
2967-
noper = noper_next;
2968-
uc= (U8*)STRING(noper);
2969-
e= uc + STR_LEN(noper);
2970-
}
2964+
if (noper_next < tail)
2965+
noper= noper_next;
29712966
}
29722967

2973-
if ( OP(noper) != NOTHING ) {
2968+
if ( noper < tail && ( OP(noper) == flags || ( flags == EXACTFU && OP(noper) == EXACTFU_SS ) ) ) {
2969+
const U8 *uc= (U8*)STRING(noper);
2970+
const U8 *e= uc + STR_LEN(noper);
2971+
29742972
for ( ; uc < e ; uc += len ) {
29752973

29762974
TRIE_READ_CHAR;

0 commit comments

Comments
 (0)