Skip to content

Commit 07e635f

Browse files
committed
Merge pull request #435 from redboltz/fix_433
Fix 433
2 parents 549c284 + b641065 commit 07e635f

File tree

5 files changed

+440
-21
lines changed

5 files changed

+440
-21
lines changed

include/msgpack/v1/adaptor/map.hpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,16 @@ struct convert<type::assoc_vector<K, V, Compare, Alloc> > {
7070
msgpack::object const& operator()(msgpack::object const& o, type::assoc_vector<K, V, Compare, Alloc>& v) const {
7171
if (o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
7272
v.resize(o.via.map.size);
73-
msgpack::object_kv* p = o.via.map.ptr;
74-
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
75-
std::pair<K, V>* it(&v.front());
76-
for (; p < pend; ++p, ++it) {
77-
p->key.convert(it->first);
78-
p->val.convert(it->second);
73+
if (o.via.map.size != 0) {
74+
msgpack::object_kv* p = o.via.map.ptr;
75+
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
76+
std::pair<K, V>* it(&v.front());
77+
for (; p < pend; ++p, ++it) {
78+
p->key.convert(it->first);
79+
p->val.convert(it->second);
80+
}
81+
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>());
7982
}
80-
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K, V, Compare, Alloc>());
8183
return o;
8284
}
8385
};
@@ -192,14 +194,22 @@ struct object_with_zone<std::map<K, V, Compare, Alloc> > {
192194
}
193195
else {
194196
uint32_t size = checked_get_container_size(v.size());
197+
195198
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
196199
msgpack::object_kv* const pend = p + size;
197200
o.via.map.ptr = p;
198201
o.via.map.size = size;
199202
typename std::map<K, V, Compare, Alloc>::const_iterator it(v.begin());
200203
do {
204+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
205+
#pragma GCC diagnostic push
206+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
207+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
201208
p->key = msgpack::object(it->first, o.zone);
202209
p->val = msgpack::object(it->second, o.zone);
210+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
211+
#pragma GCC diagnostic pop
212+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
203213
++p;
204214
++it;
205215
} while(p < pend);

include/msgpack/v1/adaptor/vector_char.hpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,29 @@ struct convert<std::vector<char, Alloc> > {
3131
switch (o.type) {
3232
case msgpack::type::BIN:
3333
v.resize(o.via.bin.size);
34-
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
34+
if (o.via.bin.size != 0) {
35+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
36+
#pragma GCC diagnostic push
37+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
38+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
39+
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
40+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
41+
#pragma GCC diagnostic pop
42+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
43+
}
3544
break;
3645
case msgpack::type::STR:
3746
v.resize(o.via.str.size);
38-
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
47+
if (o.via.str.size != 0) {
48+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
49+
#pragma GCC diagnostic push
50+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
51+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
52+
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
53+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
54+
#pragma GCC diagnostic pop
55+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
56+
}
3957
break;
4058
default:
4159
throw msgpack::type_error();
@@ -51,7 +69,9 @@ struct pack<std::vector<char, Alloc> > {
5169
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<char, Alloc>& v) const {
5270
uint32_t size = checked_get_container_size(v.size());
5371
o.pack_bin(size);
54-
o.pack_bin_body(&v.front(), size);
72+
if (size != 0) {
73+
o.pack_bin_body(&v.front(), size);
74+
}
5575

5676
return o;
5777
}
@@ -62,7 +82,9 @@ struct object<std::vector<char, Alloc> > {
6282
void operator()(msgpack::object& o, const std::vector<char, Alloc>& v) const {
6383
uint32_t size = checked_get_container_size(v.size());
6484
o.type = msgpack::type::BIN;
65-
o.via.bin.ptr = &v.front();
85+
if (size != 0) {
86+
o.via.bin.ptr = &v.front();
87+
}
6688
o.via.bin.size = size;
6789
}
6890
};
@@ -72,10 +94,12 @@ struct object_with_zone<std::vector<char, Alloc> > {
7294
void operator()(msgpack::object::with_zone& o, const std::vector<char, Alloc>& v) const {
7395
uint32_t size = checked_get_container_size(v.size());
7496
o.type = msgpack::type::BIN;
75-
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
76-
o.via.bin.ptr = ptr;
7797
o.via.bin.size = size;
78-
std::memcpy(ptr, &v.front(), size);
98+
if (size != 0) {
99+
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
100+
o.via.bin.ptr = ptr;
101+
std::memcpy(ptr, &v.front(), size);
102+
}
79103
}
80104
};
81105

include/msgpack/v1/adaptor/vector_unsigned_char.hpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,29 @@ struct convert<std::vector<unsigned char, Alloc> > {
3131
switch (o.type) {
3232
case msgpack::type::BIN:
3333
v.resize(o.via.bin.size);
34-
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
34+
if (o.via.bin.size != 0) {
35+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
36+
#pragma GCC diagnostic push
37+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
38+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
39+
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
40+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
41+
#pragma GCC diagnostic pop
42+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
43+
}
3544
break;
3645
case msgpack::type::STR:
3746
v.resize(o.via.str.size);
38-
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
47+
if (o.via.str.size != 0) {
48+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
49+
#pragma GCC diagnostic push
50+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
51+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
52+
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
53+
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
54+
#pragma GCC diagnostic pop
55+
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
56+
}
3957
break;
4058
default:
4159
throw msgpack::type_error();
@@ -51,7 +69,9 @@ struct pack<std::vector<unsigned char, Alloc> > {
5169
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<unsigned char, Alloc>& v) const {
5270
uint32_t size = checked_get_container_size(v.size());
5371
o.pack_bin(size);
54-
o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size);
72+
if (size != 0) {
73+
o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size);
74+
}
5575

5676
return o;
5777
}
@@ -62,7 +82,9 @@ struct object<std::vector<unsigned char, Alloc> > {
6282
void operator()(msgpack::object& o, const std::vector<unsigned char, Alloc>& v) const {
6383
uint32_t size = checked_get_container_size(v.size());
6484
o.type = msgpack::type::BIN;
65-
o.via.bin.ptr = reinterpret_cast<char const*>(&v.front());
85+
if (size != 0) {
86+
o.via.bin.ptr = reinterpret_cast<char const*>(&v.front());
87+
}
6688
o.via.bin.size = size;
6789
}
6890
};
@@ -72,10 +94,12 @@ struct object_with_zone<std::vector<unsigned char, Alloc> > {
7294
void operator()(msgpack::object::with_zone& o, const std::vector<unsigned char, Alloc>& v) const {
7395
uint32_t size = checked_get_container_size(v.size());
7496
o.type = msgpack::type::BIN;
75-
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
76-
o.via.bin.ptr = ptr;
7797
o.via.bin.size = size;
78-
std::memcpy(ptr, &v.front(), size);
98+
if (size != 0) {
99+
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
100+
o.via.bin.ptr = ptr;
101+
std::memcpy(ptr, &v.front(), size);
102+
}
79103
}
80104
};
81105

0 commit comments

Comments
 (0)