1
0
forked from Mirror/wren

Don't overflow signature string if there are too many parameters.

Fix #494.
This commit is contained in:
Bob Nystrom
2018-04-27 09:13:40 -07:00
parent c5ce6fac46
commit 8fae8e4f1e
2 changed files with 8 additions and 1 deletions

View File

@ -1704,7 +1704,11 @@ static void signatureParameterList(char name[MAX_METHOD_SIGNATURE], int* length,
int numParams, char leftBracket, char rightBracket) int numParams, char leftBracket, char rightBracket)
{ {
name[(*length)++] = leftBracket; name[(*length)++] = leftBracket;
for (int i = 0; i < numParams; i++)
// This function may be called with too many parameters. When that happens,
// a compile error has already been reported, but we need to make sure we
// don't overflow the string too, hence the MAX_PARAMETERS check.
for (int i = 0; i < numParams && i < MAX_PARAMETERS; i++)
{ {
if (i > 0) name[(*length)++] = ','; if (i > 0) name[(*length)++] = ',';
name[(*length)++] = '_'; name[(*length)++] = '_';

3
test/regression/494.wren Normal file
View File

@ -0,0 +1,3 @@
0[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
// expect error line 1
// expect error line 4