0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-11-30 00:56:44 +01:00

More asserts in AlignedBuilder

This commit is contained in:
Mathias Stearn 2011-01-18 23:42:27 -05:00
parent 85f4700e91
commit 8631bb6aad

View File

@ -27,6 +27,8 @@ namespace mongo {
uassert(13584, "out of memory AlignedBuilder", _p._allocationAddress); uassert(13584, "out of memory AlignedBuilder", _p._allocationAddress);
} }
BOOST_STATIC_ASSERT(sizeof(void*) == sizeof(size_t));
void AlignedBuilder::mallocSelfAligned(unsigned sz) { void AlignedBuilder::mallocSelfAligned(unsigned sz) {
assert( sz == _p._size ); assert( sz == _p._size );
void *p = malloc(sz + Alignment - 1); void *p = malloc(sz + Alignment - 1);
@ -35,7 +37,8 @@ namespace mongo {
size_t sold = s; size_t sold = s;
s += Alignment - 1; s += Alignment - 1;
s = (s/Alignment)*Alignment; s = (s/Alignment)*Alignment;
DEV assert( s >= sold ); assert( s >= sold ); // begining
assert( (s + sz) <= (sold + Alignment - 1) ); //end
_p._data = (char *) s; _p._data = (char *) s;
} }