@@ -92,15 +92,17 @@ template<class Allocator>
92
92
bool test_allocation_shrink (Allocator &a)
93
93
{
94
94
std::vector<void *> buffers;
95
+ std::vector<std::size_t > sizes;
95
96
96
97
// Allocate buffers with extra memory
97
98
for (std::size_t i = 0 ; true ; ++i){
98
99
void *ptr = a.allocate (i*2 , std::nothrow);
99
100
if (!ptr)
100
101
break ;
101
- std::size_t size = a.size (ptr);
102
+ std::size_t size = a.size (ptr);
102
103
std::memset (ptr, 0 , size);
103
104
buffers.push_back (ptr);
105
+ sizes.push_back (size);
104
106
}
105
107
106
108
// Now shrink to half
@@ -110,15 +112,20 @@ bool test_allocation_shrink(Allocator &a)
110
112
typename Allocator::size_type received_size;
111
113
char *reuse = static_cast <char *>(buffers[i]);
112
114
if (a.template allocation_command <char >
113
- ( boost::interprocess::shrink_in_place | boost::interprocess::nothrow_allocation, i* 2
115
+ ( boost::interprocess::shrink_in_place | boost::interprocess::nothrow_allocation, sizes[i]
114
116
, received_size = i, reuse)){
115
- if (received_size > std::size_t (i* 2 ) ){
117
+ if (received_size > sizes[i] ){
116
118
return false ;
117
119
}
118
120
if (received_size < std::size_t (i)){
119
121
return false ;
120
122
}
121
- std::memset (buffers[i], 0 , a.size (buffers[i]));
123
+ const std::size_t sz = a.size (buffers[i]);
124
+ if (received_size != sz) {
125
+ return false ;
126
+ }
127
+
128
+ std::memset (buffers[i], 0 , sz);
122
129
}
123
130
}
124
131
0 commit comments