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.
This commit is contained in:
Fischlurch 2012-02-19 00:41:45 +01:00
parent 1e54b5d3e6
commit 0b25c2e08d
2 changed files with 8 additions and 6 deletions

View file

@ -132,12 +132,14 @@ namespace lib {
#define TYPE_SANITY_CHECK \
BOOST_STATIC_ASSERT ((boost::is_base_of<I,TY>::value || boost::is_same<I,TY>::value))
#define TYPE_AND_STORAGE_SANITY_CHECK \
BOOST_STATIC_ASSERT (((boost::is_same<I,TY>::value \
||boost::is_base_of<I,TY>::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
};

View file

@ -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<Dummy> CollD;
typedef ScopedCollection<Dummy, sizeof(SubDummy)> CollD;
/********************************************************************