Check array size for overflow.
Since ZScript is a 32 bit VM, the largest safe value for an array's physical size is 2GB. Any larger value will be destroyed by the compiler which relies on signed 32 bit values too much.
This commit is contained in:
parent
adeb48d598
commit
2cbb980388
1 changed files with 5 additions and 0 deletions
|
|
@ -2286,6 +2286,11 @@ PType *ZCCCompiler::ResolveArraySize(PType *baseType, ZCC_Expression *arraysize,
|
|||
Error(arraysize, "Array size must be positive");
|
||||
return TypeError;
|
||||
}
|
||||
if (uint64_t(size) * baseType->Size > 0x7fffffff)
|
||||
{
|
||||
Error(arraysize, "Array size overflow. Total size must be less than 2GB");
|
||||
return TypeError;
|
||||
}
|
||||
baseType = NewArray(baseType, size);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue