(svn r22875) -Codechange: Add some asserts and checks to better prevent overflow of the argument to malloc. (monoid)

This commit is contained in:
michi_cc
2011-09-02 20:54:51 +00:00
parent 65637d8941
commit f227e90c24
6 changed files with 22 additions and 1 deletions

View File

@@ -53,6 +53,9 @@ public:
/** Default constructor. Preallocate space for items and header, then initialize header. */
FixedSizeArray()
{
/* Ensure the size won't overflow. */
assert_compile(C < (SIZE_MAX - HeaderSize) / Tsize);
/* allocate block for header + items (don't construct items) */
data = (T*)((MallocT<byte>(HeaderSize + C * Tsize)) + HeaderSize);
SizeRef() = 0; // initial number of items