Skip to content

Commit

Permalink
fix: possible memory error in calling macros with arguments (#434)
Browse files Browse the repository at this point in the history
The pointer to the currently processed preprocessor variable is
invalidated when the list of preprocessor variables is extended.

Close #434.
  • Loading branch information
tueda committed Mar 7, 2023
1 parent b1836d6 commit 741861a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions check/fixes.frm
Original file line number Diff line number Diff line change
Expand Up @@ -2285,3 +2285,15 @@ Print +s;
assert succeeded?
assert result("F3") =~ expr("+D")
*--#] Issue405 :
*--#[ Issue434 :
* Memory error with macros with arguments
* The loop (appending a variable and calling the macro) is repeated enough
* to hit the problem (Valgrind error).
#define var(a) "`~a'"
#do n=1,{12*2^5}
#define x
#message `var(`n')'
#enddo
.end
assert succeeded?
*--#] Issue434 :
3 changes: 3 additions & 0 deletions sources/pre.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ UBYTE GetChar(int level)
*/
int nargs = 1;
PREVAR *p;
size_t p_offset;
*s++ = 0; namebuf[i-2] = 0;
if ( StrICmp(namebuf,(UBYTE *)"random_") == 0 ) {
UBYTE *ranvalue;
Expand Down Expand Up @@ -367,6 +368,7 @@ UBYTE GetChar(int level)
while ( *s ) s++;
s++;
t = p->argnames;
p_offset = p - PreVar;
for ( j = 0; j < p->nargs; j++ ) {
if ( ( nargs == p->nargs-1 ) && ( *t == '?' ) ) {
PutPreVar(t,0,0,0);
Expand All @@ -376,6 +378,7 @@ UBYTE GetChar(int level)
while ( *s ) s++;
s++;
}
p = PreVar + p_offset;
while ( *t ) t++;
t++;
}
Expand Down

0 comments on commit 741861a

Please sign in to comment.