From 6c888ac563d0b074158ef4104821d7d2eecd91db Mon Sep 17 00:00:00 2001 From: Josh Davies Date: Mon, 16 Jun 2025 21:19:20 +0100 Subject: [PATCH 1/2] fix: ignore empty functions in transform addargs/mulargs --- check/fixes.frm | 13 +++++++++++++ sources/transform.c | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/check/fixes.frm b/check/fixes.frm index 314bfdc7..1476a6e1 100644 --- a/check/fixes.frm +++ b/check/fixes.frm @@ -2331,6 +2331,19 @@ P; #pend_if mpi? assert runtime_error? *--#] Issue261_7 : +*--#[ Issue267 : +#- +CFunction f,g,h,i; +Local test = f + g + h(1,2) + i(1,2) + h(1,2,3) + i(1,2,3); +Transform f addargs(1,last); +Transform g mulargs(1,last); +Transform h addargs(1,3); +Transform i mulargs(1,3); +Print; +.end +assert succeeded? +assert result("test") =~ expr("f + g + h(1,2) + h(6) + i(2) + i(6)"); +*--#] Issue267 : *--#[ Issue268_1 : * Invalid read in Normalize #define N "9999" diff --git a/sources/transform.c b/sources/transform.c index 392cd2a1..4cb712e7 100644 --- a/sources/transform.c +++ b/sources/transform.c @@ -2703,6 +2703,8 @@ WORD RunAddArg(PHEAD WORD *fun, WORD *args) } tt = fun+FUNHEAD; tstop = fun+fun[1]; totarg = 0; while ( tt < tstop ) { totarg++; NEXTARG(tt); } + /* ignore functions with no arguments */ + if ( totarg == 0 ) return(0); if ( FindRange(BHEAD args,&arg1,&arg2,totarg) ) return(-1); /* We need to: @@ -2791,6 +2793,8 @@ WORD RunMulArg(PHEAD WORD *fun, WORD *args) } t = fun+FUNHEAD; tstop = fun+fun[1]; totarg = 0; while ( t < tstop ) { totarg++; NEXTARG(t); } + /* ignore functions with no arguments */ + if ( totarg == 0 ) return(0); if ( FindRange(BHEAD args,&arg1,&arg2,totarg) ) return(-1); if ( arg2 < arg1 ) { n = arg1; arg1 = arg2; arg2 = n; } if ( arg1 > totarg ) return(0); From 1586eb4140f5ee5443f9349c71e3307dacb950b3 Mon Sep 17 00:00:00 2001 From: Josh Davies Date: Mon, 16 Jun 2025 21:43:53 +0100 Subject: [PATCH 2/2] fix: correct error message for 0 range specifier in transform --- sources/transform.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/sources/transform.c b/sources/transform.c index 4cb712e7..c1b9a51a 100644 --- a/sources/transform.c +++ b/sources/transform.c @@ -3556,20 +3556,25 @@ int FindRange(PHEAD WORD *args, WORD *arg1, WORD *arg2, WORD totarg) n[i] -= MAXPOSITIVE4; /* Now we have the number of the dollar variable */ } n[i] = DolToNumber(BHEAD n[i]); - if ( AN.ErrorInDollar ) goto Error; + if ( AN.ErrorInDollar ) { + MLOCK(ErrorMessageLock); + MesPrint("Illegal $ value in range while executing transform statement."); + MUNLOCK(ErrorMessageLock); + return(-1); + } if ( fromlast ) n[i] = totarg-n[i]; } else if ( n[i] >= MAXPOSITIVE4 ) { n[i] = totarg-(n[i]-MAXPOSITIVE4); } - if ( n[i] <= 0 ) goto Error; + if ( n[i] <= 0 ) { + MLOCK(ErrorMessageLock); + MesPrint("Illegal non-positive value in range (%d) while executing transform statement.", i+1); + MUNLOCK(ErrorMessageLock); + return(-1); + } } *arg1 = n[0]; *arg2 = n[1]; return(0); -Error: - MLOCK(ErrorMessageLock); - MesPrint("Illegal $ value in range while executing transform statement."); - MUNLOCK(ErrorMessageLock); - return(-1); } /*