Skip to content

Commit 42d5d20

Browse files
committed
Fix shrink test using real buffer sizes instead of requested sizes
1 parent ab9b562 commit 42d5d20

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

test/memory_algorithm_test_template.hpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,17 @@ template<class Allocator>
9292
bool test_allocation_shrink(Allocator &a)
9393
{
9494
std::vector<void*> buffers;
95+
std::vector<std::size_t> sizes;
9596

9697
//Allocate buffers with extra memory
9798
for(std::size_t i = 0; true; ++i){
9899
void *ptr = a.allocate(i*2, std::nothrow);
99100
if(!ptr)
100101
break;
101-
std::size_t size = a.size(ptr);
102+
std::size_t size = a.size(ptr);
102103
std::memset(ptr, 0, size);
103104
buffers.push_back(ptr);
105+
sizes.push_back(size);
104106
}
105107

106108
//Now shrink to half
@@ -110,15 +112,20 @@ bool test_allocation_shrink(Allocator &a)
110112
typename Allocator::size_type received_size;
111113
char *reuse = static_cast<char*>(buffers[i]);
112114
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]
114116
, received_size = i, reuse)){
115-
if(received_size > std::size_t(i*2)){
117+
if(received_size > sizes[i]){
116118
return false;
117119
}
118120
if(received_size < std::size_t(i)){
119121
return false;
120122
}
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);
122129
}
123130
}
124131

0 commit comments

Comments
 (0)