mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-02-16 17:21:10 +00:00
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
ee6991e6d8
commit
a14bba3561
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…
Reference in a new issue