From 0b25c2e08d469a10e514aa2112961bdfbc35786a Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sun, 19 Feb 2012 00:41:45 +0100 Subject: [PATCH] Fix: missing sanity check in ScopedCollection funny enough this possible memory corruption didn't happen in the unit test, because my compiler optimised the additional int field of class SubDummy, making it the same size of the baseclass. Now matters should be safe. --- src/lib/scoped-collection.hpp | 10 ++++++---- tests/lib/scoped-collection-test.cpp | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lib/scoped-collection.hpp b/src/lib/scoped-collection.hpp index 0ff2d37ef..729c88495 100644 --- a/src/lib/scoped-collection.hpp +++ b/src/lib/scoped-collection.hpp @@ -132,12 +132,14 @@ namespace lib { -#define TYPE_SANITY_CHECK \ - BOOST_STATIC_ASSERT ((boost::is_base_of::value || boost::is_same::value)) +#define TYPE_AND_STORAGE_SANITY_CHECK \ + BOOST_STATIC_ASSERT (((boost::is_same::value \ + ||boost::is_base_of::value)\ + && sizeof(TY) <= siz)) /** Abbreviation for placement new */ #define EMBEDDED_ELEMENT_CTOR(_CTOR_CALL_) \ - TYPE_SANITY_CHECK; \ + TYPE_AND_STORAGE_SANITY_CHECK; \ return *new(&buf_) _CTOR_CALL_; \ @@ -205,8 +207,8 @@ namespace lib { { EMBEDDED_ELEMENT_CTOR ( TY(a1,a2,a3,a4,a5) ) } +#undef TYPE_AND_STORAGE_SANITY_CHECK #undef EMBEDDED_ELEMENT_CTOR -#undef TYPE_SANITY_CHECK }; diff --git a/tests/lib/scoped-collection-test.cpp b/tests/lib/scoped-collection-test.cpp index f112e79da..c2408d7dc 100644 --- a/tests/lib/scoped-collection-test.cpp +++ b/tests/lib/scoped-collection-test.cpp @@ -78,7 +78,7 @@ namespace test{ inline uint sum (uint n) { - return n*(n+1) / 2; + return n*(n+1) / 2; } }//(End) subversive test data @@ -89,7 +89,7 @@ namespace test{ using util::isnil; using lumiera::error::LUMIERA_ERROR_ITER_EXHAUST; - typedef ScopedCollection CollD; + typedef ScopedCollection CollD; /********************************************************************