Stricter bounds for memory arrays.

This commit is contained in:
Daniel Kirchner
2020-04-16 17:51:18 +02:00
parent f6d1cee06b
commit 150497c12a
3 changed files with 31 additions and 2 deletions
+16 -1
View File
@@ -1663,7 +1663,22 @@ BoolResult ArrayType::validForLocation(DataLocation _loc) const
{
case DataLocation::Memory:
{
bigint size = bigint(length()) * m_baseType->memoryHeadSize();
bigint size = bigint(length());
auto type = m_baseType;
while (auto arrayType = dynamic_cast<ArrayType const*>(type))
{
if (arrayType->isDynamicallySized())
break;
else
{
size *= arrayType->length();
type = arrayType->baseType();
}
}
if (type->isDynamicallySized())
size *= type->memoryHeadSize();
else
size *= type->memoryDataSize();
if (size >= numeric_limits<unsigned>::max())
return BoolResult::err("Type too large for memory.");
break;