Skip to content

Commit 9bb422b

Browse files
committed
Fix crash due to empty set restriction in wildcard match
Closes form-dev#554
1 parent fbd8579 commit 9bb422b

File tree

2 files changed

+99
-0
lines changed

2 files changed

+99
-0
lines changed

check/fixes.frm

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3132,6 +3132,94 @@ Print +s;
31323132
assert succeeded?
31333133
assert result("test") =~ expr("0")
31343134
*--#] Issue544 :
3135+
*--#[ Issue554_1 :
3136+
CF f;
3137+
S x;
3138+
L F = f(x);
3139+
id f(x?{}) = x;
3140+
print;
3141+
.end
3142+
assert succeeded?
3143+
assert result("F") =~ expr("f(x)")
3144+
*--#] Issue554_1 :
3145+
*--#[ Issue554_2 :
3146+
CF f;
3147+
S x;
3148+
L F = f(x);
3149+
id f(x?!{}) = x;
3150+
print;
3151+
.end
3152+
assert succeeded?
3153+
assert result("F") =~ expr("x")
3154+
*--#] Issue554_2 :
3155+
*--#[ Issue554_3 :
3156+
CF f;
3157+
S x;
3158+
Set empty: ;
3159+
L F = f(x);
3160+
id f(x?empty) = x;
3161+
print;
3162+
.end
3163+
assert succeeded?
3164+
assert result("F") =~ expr("f(x)")
3165+
*--#] Issue554_3 :
3166+
*--#[ Issue554_4 :
3167+
CF f;
3168+
S x;
3169+
Set empty: ;
3170+
L F = f(x);
3171+
id f(x?!empty) = x;
3172+
print;
3173+
.end
3174+
assert succeeded?
3175+
assert result("F") =~ expr("x")
3176+
*--#] Issue554_4 :
3177+
*--#[ Issue554_5 :
3178+
CF f;
3179+
S x,y;
3180+
L F = f(1)+f(2)+f(3);
3181+
id f(x?{}) = x;
3182+
id f(y?{1,2}) = x^y;
3183+
print;
3184+
.end
3185+
assert succeeded?
3186+
assert result("F") =~ expr("x + x^2 + f(3)")
3187+
*--#] Issue554_5 :
3188+
*--#[ Issue554_6 :
3189+
#-
3190+
CF f,g,h,i;
3191+
S x;
3192+
3193+
#$x1 = f(1,3,5);
3194+
#$x2 = f();
3195+
3196+
#inside $x1
3197+
if (match(f(?a$a)));
3198+
endif;
3199+
#endinside
3200+
#inside $x2
3201+
if (match(f(?a$b)));
3202+
endif;
3203+
#endinside
3204+
3205+
L F = f(1,2,3,4,5,6);
3206+
L G = g(1,2,3,4,5,6);
3207+
L H = h(1,2,3,4,5,6);
3208+
L I = i(1,2,3,4,5,6);
3209+
3210+
repeat id f(?a,x? {`$a',},?b) = x * f(?a,?b);
3211+
repeat id g(?a,x?!{`$a',},?b) = x * g(?a,?b);
3212+
repeat id h(?a,x? {`$b',},?b) = x * h(?a,?b);
3213+
repeat id i(?a,x?!{`$b',},?b) = x * i(?a,?b);
3214+
3215+
P;
3216+
.end
3217+
assert succeeded?
3218+
assert result("F") =~ expr("15*f(2,4,6)")
3219+
assert result("G") =~ expr("48*g(1,3,5)")
3220+
assert result("H") =~ expr("h(1,2,3,4,5,6)")
3221+
assert result("I") =~ expr("720*i")
3222+
*--#] Issue554_6 :
31353223
*--#[ Issue563 :
31363224
#: SubTermsInSmall 64
31373225

sources/wildcard.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,17 @@ WORD CheckWild(PHEAD WORD oldnumber, WORD type, WORD newnumber, WORD *newval)
22572257
*/
22582258
w = SetElements + Sets[j].first;
22592259
m = SetElements + Sets[j].last;
2260+
if ( w == m ) {
2261+
/*
2262+
The set is empty! This is not a match unless we have !{}, in
2263+
which case it is.
2264+
*/
2265+
if ( notflag ) return 0;
2266+
AN.oldtype = old2;
2267+
AN.oldvalue = oldval;
2268+
goto NoMatch;
2269+
}
2270+
22602271
if ( ( Sets[j].flags & ORDEREDSET ) == ORDEREDSET ) {
22612272
/*
22622273
We search first and ask questions later

0 commit comments

Comments
 (0)