Skip to content

Commit

Permalink
Make sure SIOsize is >= MaxTermSize
Browse files Browse the repository at this point in the history
Various buffers in AllocSort depend on the IOsize parameter. At the
main level this is >= MaxTermSize, but this was not the case when
sorting function args, dollar variables.

Fixes the examples in #80 #292
  • Loading branch information
jodavies authored and tueda committed May 21, 2024
1 parent 5805922 commit c83c145
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions sources/setfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,8 @@ int AllocSetups(VOID)
AM.SMaxFpatches = sp->value;
sp = GetSetupPar((UBYTE *)"subsortiosize");
AM.SIOsize = sp->value;
/* As for IOsize, make sure SIOsize is at least as large as AM.MaxTer. */
if ( AM.SIOsize < AM.MaxTer ) { AM.SIOsize = AM.MaxTer; sp->value = AM.SIOsize; }
sp = GetSetupPar((UBYTE *)"spectatorsize");
AM.SpectatorSize = sp->value;
/*
Expand Down
7 changes: 6 additions & 1 deletion sources/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,12 @@ LONG EndSort(PHEAD WORD *buffer, int par)
UNLOCK(newout->pthreadslock);
#endif
}
else if ( newout->handle >= 0 ) { /* output too large */
else if ( newout->handle >= 0 ) {
/*
We land here if par == 1 (function arg sort) and PutOut has created a file.
This means that the term is larger than SIOsize, which we ensure is at least
as large as MaxTermSize in setfile.c. Thus we know already that the term won't fit.
*/
TooLarge:
MLOCK(ErrorMessageLock);
MesPrint("(1)Output should fit inside a single term. Increase MaxTermSize?");
Expand Down

0 comments on commit c83c145

Please sign in to comment.