Skip to content

Commit

Permalink
Fix termination when saving long-named expressions in a pre-proc loop
Browse files Browse the repository at this point in the history
It was not intended in #500 that this warning crashes form, which happened
here when Save was called in a pre-processor loop. This is due to the
leading & of the message which triggers the source file line information.
Warning protects from the crash by temporarily setting the "iswarning"
variable which causes MesPrint to then not terminate.

This can be easily cleaned up later if Warning is refactored to take a
format string and variable arguments.
  • Loading branch information
jodavies committed Oct 16, 2024
1 parent 9650165 commit 61ecfdd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions check/fixes.frm
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,18 @@ Save test.res abcdefghijklmnop;
.end
assert succeeded?
*--#] Issue192_3 :
*--#[ Issue192_4 :
* Also related: Issue 334.
Global abcdefghijklmnop1 = 17;
Global abcdefghijklmnop2 = 17;
.store
#do i = 1,2
Save test.res abcdefghijklmnop`i';
#enddo
.end
assert warning?("saved expr name over 16 char: abcdefghijklmnop1")
assert warning?("saved expr name over 16 char: abcdefghijklmnop2")
*--#] Issue192_4 :
*--#[ Issue197 :
* mul_ ignores denominator factors
#if "{2^32}" == "0"
Expand Down
8 changes: 6 additions & 2 deletions sources/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ int CoSave(UBYTE *inp)
if ( GetVar(inp,&type,&number,CEXPRESSION,NOAUTO) != NAMENOTFOUND ) {
if ( e[number].status == STOREDEXPRESSION ) {
if ( StrLen(AC.exprnames->namebuffer+e[number].name) > MAXENAME ) {
MesPrint("&Warning: saved expr name over %d char: %s", MAXENAME, AC.exprnames->namebuffer+e[number].name);
char msg[100];
snprintf(msg, sizeof(msg), "saved expr name over %d char: %s", MAXENAME, AC.exprnames->namebuffer+e[number].name);
Warning(msg);
}
/*
Here we have to locate the stored expression, copy its index entry
Expand Down Expand Up @@ -525,7 +527,9 @@ NextExpr:;
/* Make sure there is at least one stored expression: */
if ( n > 0 ) { do {
if ( StrLen(AC.exprnames->namebuffer+e->name) > MAXENAME ) {
MesPrint("&Warning: saved expr name over %d char: %s", MAXENAME, AC.exprnames->namebuffer+e->name);
char msg[100];
snprintf(msg, sizeof(msg), "saved expr name over %d char: %s", MAXENAME, AC.exprnames->namebuffer+e->name);
Warning(msg);
}
if ( e->status == STOREDEXPRESSION ) exprInStorageFlag = 1;
e++;
Expand Down

0 comments on commit 61ecfdd

Please sign in to comment.