Fix bug in processing UNTIL clause.

Bug found by Ian! D. Allen.
This commit is contained in:
Dianne Skoll
2025-06-15 09:15:48 -04:00
parent b6e53341c8
commit 37e09f4671
3 changed files with 27 additions and 14 deletions

View File

@@ -310,15 +310,15 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart
{
int simple, mod, omit;
/* First: Have we passed the UNTIL date? */
/* First: Have we passed the UNTIL date? */
if (trig->until != NO_UNTIL &&
trig->until < start) {
trig->expired = 1;
return -1; /* expired */
}
/* Next: If it's an "AFTER"-type skip, back up
until we're at the start of a block of holidays */
/* Next: If it's an "AFTER"-type skip, back up
until we're at the start of a block of holidays */
if (trig->skip == AFTER_SKIP) {
int iter = 0;
while (iter++ <= MaxSatIter) {
@@ -339,16 +339,16 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart
}
}
/* Find the next simple trigger */
/* Find the next simple trigger */
simple = NextSimpleTrig(start, trig, err);
/* Problems? */
/* Problems? */
if (*err || (simple == -1)) return -1;
/* Suggested starting point for next attempt */
/* Suggested starting point for next attempt */
*nextstart = simple+1;
/* If there's a BACK, back up... */
/* If there's a BACK, back up... */
if (trig->back != NO_BACK) {
mod = trig->back;
if (mod < 0) {
@@ -376,7 +376,7 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart
}
}
/* If there's a REP, calculate the next occurrence */
/* If there's a REP, calculate the next occurrence */
if (trig->rep != NO_REP) {
if (simple < start) {
mod = (start - simple) / trig->rep;
@@ -385,7 +385,7 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart
}
}
/* If it's a "BEFORE"-type skip, back up */
/* If it's a "BEFORE"-type skip, back up */
if (trig->skip == BEFORE_SKIP) {
int iter = 0;
while(iter++ <= MaxSatIter) {
@@ -406,7 +406,7 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart
}
}
/* If it's an "AFTER"-type skip, jump ahead */
/* If it's an "AFTER"-type skip, jump ahead */
if (trig->skip == AFTER_SKIP) {
int iter = 0;
while (iter++ <= MaxSatIter) {
@@ -423,7 +423,12 @@ static int GetNextTriggerDate(Trigger *trig, int start, int *err, int *nextstart
}
}
/* Return the date */
/* If we've passed the UNTIL, then it's expired */
if (trig->until != NO_UNTIL && simple > trig->until) {
return -1;
}
/* Return the date */
return simple;
}

View File

@@ -3153,7 +3153,7 @@ REM Mon 1992 UNTIL 1991-01-01 MSG Not diagnosed - not fully-specified start
../tests/test.rem(561): Expired
REM 1992-01-01 *1 UNTIL 1991-12-31 MSG Diagnosed
../tests/test.rem(562): Warning: UNTIL/THROUGH date earlier than start date
../tests/test.rem(562): Trig = Wednesday, 1 January, 1992
../tests/test.rem(562): Expired
set x '1992-01-01'
MSG [isconst(x)]
../tests/test.rem(564): Trig = Saturday, 16 February, 1991
@@ -3164,7 +3164,7 @@ isconst(1992-01-01) => 1
REM [x] *1 UNTIL 1991-12-31 MSG Diagnosed
x => 1992-01-01
../tests/test.rem(565): Warning: UNTIL/THROUGH date earlier than start date
../tests/test.rem(565): Trig = Wednesday, 1 January, 1992
../tests/test.rem(565): Expired
set x nonconst('1992-01-01')
nonconst(1992-01-01) => 1992-01-01
@@ -3176,7 +3176,7 @@ isconst(1992-01-01) => 0
REM [x] *1 UNTIL 1991-12-31 MSG Not diagnosed - nonconst expression
x => 1992-01-01
../tests/test.rem(569): Trig = Wednesday, 1 January, 1992
../tests/test.rem(569): Expired
REM MON FROM 1992-01-01 UNTIL 1991-12-31 MSG Diagnosed
../tests/test.rem(571): Warning: UNTIL/THROUGH date earlier than FROM date
@@ -16575,6 +16575,8 @@ DEBUG -e
../tests/test.rem(1603): eval(): Too many recursive function calls
Base: 1991-02-09
Base: 1991-02-09
../tests/test.rem(1611): Expired
../tests/test.rem(1612): Expired
Variable hash table statistics:
Entries: 100143; Buckets: 87719; Non-empty Buckets: 66301
Maxlen: 5; Minlen: 0; Avglen: 1.142; Stddev: 0.878; Avg nonempty len: 1.510

View File

@@ -1606,6 +1606,12 @@ set a eval(a)
REM 9 Feb 1991 *7 MSG Base: [trigbase()]
REM 9 Feb 1991 *1 MSG Base: [$Tb]
# The UNTIL bug
DEBUG +t
REM SECOND SATURDAY +300 UNTIL 1991-02-02 MSG [$T]
REM SECOND SATURDAY +300 UNTIL 1991-02-16 MSG [$T]
DEBUG -t
# Output expression-node stats
DEBUG +h