Implement the "unreasonable array allocation" OutOfMemoryError.
This doesn't fix test 061 because we still need AllocWithGrowth, but at least
it gets us far enough to need that.
Change-Id: Ia7b4a1f91a31e25d439f36b17280ce21c9ed8933
diff --git a/src/object.h b/src/object.h
index 42235b8..205d7c0 100644
--- a/src/object.h
+++ b/src/object.h
@@ -1107,11 +1107,6 @@
class MANAGED Array : public Object {
public:
- static size_t SizeOf(size_t component_count,
- size_t component_size) {
- return sizeof(Array) + component_count * component_size;
- }
-
// A convenience for code that doesn't know the component size,
// and doesn't want to have to work it out itself.
static Array* Alloc(Class* array_class, int32_t component_count);
@@ -2226,7 +2221,8 @@
}
inline size_t Array::SizeOf() const {
- return SizeOf(GetLength(), GetClass()->GetComponentSize());
+ // This is safe from overflow because the array was already allocated, so we know it's sane.
+ return sizeof(Array) + GetLength() * GetClass()->GetComponentSize();
}
template<class T>