From f227e90c248b37fe50c9e48a08a1bb976c782e9f Mon Sep 17 00:00:00 2001 From: michi_cc Date: Fri, 2 Sep 2011 20:54:51 +0000 Subject: (svn r22875) -Codechange: Add some asserts and checks to better prevent overflow of the argument to malloc. (monoid) --- src/misc/fixedsizearray.hpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/misc/fixedsizearray.hpp') diff --git a/src/misc/fixedsizearray.hpp b/src/misc/fixedsizearray.hpp index 8b82373fa..a6f4d0c42 100644 --- a/src/misc/fixedsizearray.hpp +++ b/src/misc/fixedsizearray.hpp @@ -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(HeaderSize + C * Tsize)) + HeaderSize); SizeRef() = 0; // initial number of items -- cgit v1.2.3-54-g00ecf