@@ -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