Skip to content

Commit 1911513

Browse files
committed
Added a container size checking to vector<bool>.
All other containers have already been added it.
1 parent 7bee573 commit 1911513

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

include/msgpack/adaptor/vector_bool.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ inline msgpack::object const& operator>> (msgpack::object const& o, std::vector<
4545
template <typename Stream>
4646
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::vector<bool>& v)
4747
{
48-
o.pack_array(v.size());
48+
uint32_t size = checked_get_container_size(v.size());
49+
o.pack_array(size);
4950
for(std::vector<bool>::const_iterator it(v.begin()), it_end(v.end());
5051
it != it_end; ++it) {
5152
o.pack(static_cast<bool>(*it));
@@ -60,10 +61,11 @@ inline void operator<< (msgpack::object::with_zone& o, const std::vector<bool>&
6061
o.via.array.ptr = nullptr;
6162
o.via.array.size = 0;
6263
} else {
63-
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*v.size()));
64-
msgpack::object* const pend = p + v.size();
64+
uint32_t size = checked_get_container_size(v.size());
65+
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
66+
msgpack::object* const pend = p + size;
6567
o.via.array.ptr = p;
66-
o.via.array.size = v.size();
68+
o.via.array.size = size;
6769
std::vector<bool>::const_iterator it(v.begin());
6870
do {
6971
*p = object(static_cast<bool>(*it), o.zone);

0 commit comments

Comments
 (0)