Skip to content

Commit

Permalink
Fix crash due to empty set restriction in wildcard match
Browse files Browse the repository at this point in the history
Closes #554
  • Loading branch information
jodavies committed Jan 28, 2025
1 parent af7a786 commit 160f9d4
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
88 changes: 88 additions & 0 deletions check/fixes.frm
Original file line number Diff line number Diff line change
Expand Up @@ -3132,6 +3132,94 @@ Print +s;
assert succeeded?
assert result("test") =~ expr("0")
*--#] Issue544 :
*--#[ Issue554_1 :
CF f;
S x;
L F = f(x);
id f(x?{}) = x;
print;
.end
assert succeeded?
assert result("F") =~ expr("f(x)")
*--#] Issue554_1 :
*--#[ Issue554_2 :
CF f;
S x;
L F = f(x);
id f(x?!{}) = x;
print;
.end
assert succeeded?
assert result("F") =~ expr("x")
*--#] Issue554_2 :
*--#[ Issue554_3 :
CF f;
S x;
Set empty: ;
L F = f(x);
id f(x?empty) = x;
print;
.end
assert succeeded?
assert result("F") =~ expr("f(x)")
*--#] Issue554_3 :
*--#[ Issue554_4 :
CF f;
S x;
Set empty: ;
L F = f(x);
id f(x?!empty) = x;
print;
.end
assert succeeded?
assert result("F") =~ expr("x")
*--#] Issue554_4 :
*--#[ Issue554_5 :
CF f;
S x,y;
L F = f(1)+f(2)+f(3);
id f(x?{}) = x;
id f(y?{1,2}) = x^y;
print;
.end
assert succeeded?
assert result("F") =~ expr("x + x^2 + f(3)")
*--#] Issue554_5 :
*--#[ Issue554_6 :
#-
CF f,g,h,i;
S x;

#$x1 = f(1,3,5);
#$x2 = f();

#inside $x1
if (match(f(?a$a)));
endif;
#endinside
#inside $x2
if (match(f(?a$b)));
endif;
#endinside

L F = f(1,2,3,4,5,6);
L G = g(1,2,3,4,5,6);
L H = h(1,2,3,4,5,6);
L I = i(1,2,3,4,5,6);

repeat id f(?a,x? {`$a',},?b) = x * f(?a,?b);
repeat id g(?a,x?!{`$a',},?b) = x * g(?a,?b);
repeat id h(?a,x? {`$b',},?b) = x * h(?a,?b);
repeat id i(?a,x?!{`$b',},?b) = x * i(?a,?b);

P;
.end
assert succeeded?
assert result("F") =~ expr("15*f(2,4,6)")
assert result("G") =~ expr("48*g(1,3,5)")
assert result("H") =~ expr("h(1,2,3,4,5,6)")
assert result("I") =~ expr("720*i")
*--#] Issue554_6 :
*--#[ Issue563 :
#: SubTermsInSmall 64

Expand Down
11 changes: 11 additions & 0 deletions sources/wildcard.c
Original file line number Diff line number Diff line change
Expand Up @@ -2257,6 +2257,17 @@ WORD CheckWild(PHEAD WORD oldnumber, WORD type, WORD newnumber, WORD *newval)
*/
w = SetElements + Sets[j].first;
m = SetElements + Sets[j].last;
if ( w == m ) {
/*
The set is empty! This is not a match unless we have !{}, in
which case it is.
*/
if ( notflag ) return 0;
AN.oldtype = old2;
AN.oldvalue = oldval;
goto NoMatch;
}

if ( ( Sets[j].flags & ORDEREDSET ) == ORDEREDSET ) {
/*
We search first and ask questions later
Expand Down

0 comments on commit 160f9d4

Please sign in to comment.