Skip to content

Commit

Permalink
Fix bug where the compiler could crash trying to dereference a decaye…
Browse files Browse the repository at this point in the history
…d accessor expression used as |this|.
  • Loading branch information
David Anderson authored and psychonic committed Apr 18, 2015
1 parent d64bcc7 commit 15b6546
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions sourcepawn/compiler/sc.h
Expand Up @@ -733,6 +733,7 @@ void startfunc(char *fname);
void endfunc(void);
void alignframe(int numbytes);
void rvalue(value *lval);
void rvalue(svalue *sval);
void address(symbol *ptr,regid reg);
void store(value *lval);
void loadreg(cell address,regid reg);
Expand Down
3 changes: 2 additions & 1 deletion sourcepawn/compiler/sc3.cpp
Expand Up @@ -2784,7 +2784,8 @@ static int nesting=0;
// this reduces it to an iEXPRESSION. That's ok. We don't touch it
// otherwise though, so the type checking logic below basically acts the
// same. We are careful to not double-evaluate however.
rvalue(&implicit_this.val);
if (implicit_this.lvalue)
rvalue(&implicit_this);
pushreg(sPRI);
nest_stkusage++;
}
Expand Down
10 changes: 10 additions & 0 deletions sourcepawn/compiler/sc4.cpp
Expand Up @@ -426,6 +426,16 @@ void rvalue(value *lval)
} /* if */
}

// Wrapper that automatically markes lvalues as decayed if they are accessors,
// since it is illegal to evaluate them twice.
void rvalue(svalue *sval)
{
int ident = sval->val.ident;
rvalue(&sval->val);
if (ident == iACCESSOR)
sval->lvalue = FALSE;
}

/* Get the address of a symbol into the primary or alternate register (used
* for arrays, and for passing arguments by reference).
*/
Expand Down

0 comments on commit 15b6546

Please sign in to comment.