Merge pull request #436 from Daniel-Cortez/fix-init-selfassignment
Do not allow variables to be self-assigned through initialization
This commit is contained in:
commit
6356afbc41
@ -2359,7 +2359,10 @@ static int declloc(int fstatic)
|
||||
int ctag = tag; /* set to "tag" by default */
|
||||
int explicit_init=FALSE;/* is the variable explicitly initialized? */
|
||||
if (matchtoken('=')) {
|
||||
sym->usage &= ~uDEFINE; /* temporarily mark the variable as undefined to prevent
|
||||
* possible self-assignment through its initialization expression */
|
||||
doexpr(FALSE,FALSE,FALSE,FALSE,&ctag,NULL,TRUE);
|
||||
sym->usage |= uDEFINE;
|
||||
explicit_init=TRUE;
|
||||
} else {
|
||||
ldconst(0,sPRI); /* uninitialized variable, set to zero */
|
||||
|
@ -1833,6 +1833,8 @@ static int primary(value *lval)
|
||||
ldconst(0,sPRI); /* load 0 */
|
||||
return FALSE; /* return 0 for labels (expression error) */
|
||||
} /* if */
|
||||
if ((sym->usage & uDEFINE)==0)
|
||||
error_suggest(17,st,NULL,estSYMBOL,esfVARCONST); /* undefined symbol */
|
||||
lval->sym=sym;
|
||||
lval->ident=sym->ident;
|
||||
lval->tag=sym->tag;
|
||||
|
7
source/compiler/tests/gh_436_local_var_self_init.meta
Normal file
7
source/compiler/tests/gh_436_local_var_self_init.meta
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
'test_type': 'output_check',
|
||||
'errors': """
|
||||
gh_436_local_var_self_init.pwn(6) : error 017: undefined symbol "test"
|
||||
gh_436_local_var_self_init.pwn(7) : error 017: undefined symbol "test2"; did you mean "test"?
|
||||
"""
|
||||
}
|
9
source/compiler/tests/gh_436_local_var_self_init.pwn
Normal file
9
source/compiler/tests/gh_436_local_var_self_init.pwn
Normal file
@ -0,0 +1,9 @@
|
||||
#include <console>
|
||||
|
||||
main()
|
||||
{
|
||||
new arr[2];
|
||||
new test = test;
|
||||
new test2 = arr[test2];
|
||||
#pragma unused test, test2
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user