@@ -30,11 +30,29 @@ struct convert<std::vector<unsigned char, Alloc> > {
3030 switch (o.type ) {
3131 case msgpack::type::BIN:
3232 v.resize (o.via .bin .size );
33- std::memcpy (&v.front (), o.via .bin .ptr , o.via .bin .size );
33+ if (o.via .bin .size != 0 ) {
34+ #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
35+ #pragma GCC diagnostic push
36+ #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
37+ #endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
38+ std::memcpy (&v.front (), o.via .bin .ptr , o.via .bin .size );
39+ #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
40+ #pragma GCC diagnostic pop
41+ #endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
42+ }
3443 break ;
3544 case msgpack::type::STR:
3645 v.resize (o.via .str .size );
37- std::memcpy (&v.front (), o.via .str .ptr , o.via .str .size );
46+ if (o.via .str .size != 0 ) {
47+ #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
48+ #pragma GCC diagnostic push
49+ #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
50+ #endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
51+ std::memcpy (&v.front (), o.via .str .ptr , o.via .str .size );
52+ #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
53+ #pragma GCC diagnostic pop
54+ #endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
55+ }
3856 break ;
3957 default :
4058 throw msgpack::type_error ();
@@ -50,7 +68,9 @@ struct pack<std::vector<unsigned char, Alloc> > {
5068 msgpack::packer<Stream>& operator ()(msgpack::packer<Stream>& o, const std::vector<unsigned char , Alloc>& v) const {
5169 uint32_t size = checked_get_container_size (v.size ());
5270 o.pack_bin (size);
53- o.pack_bin_body (reinterpret_cast <char const *>(&v.front ()), size);
71+ if (size != 0 ) {
72+ o.pack_bin_body (reinterpret_cast <char const *>(&v.front ()), size);
73+ }
5474
5575 return o;
5676 }
@@ -61,7 +81,9 @@ struct object<std::vector<unsigned char, Alloc> > {
6181 void operator ()(msgpack::object& o, const std::vector<unsigned char , Alloc>& v) const {
6282 uint32_t size = checked_get_container_size (v.size ());
6383 o.type = msgpack::type::BIN;
64- o.via .bin .ptr = reinterpret_cast <char const *>(&v.front ());
84+ if (size != 0 ) {
85+ o.via .bin .ptr = reinterpret_cast <char const *>(&v.front ());
86+ }
6587 o.via .bin .size = size;
6688 }
6789};
@@ -71,10 +93,12 @@ struct object_with_zone<std::vector<unsigned char, Alloc> > {
7193 void operator ()(msgpack::object::with_zone& o, const std::vector<unsigned char , Alloc>& v) const {
7294 uint32_t size = checked_get_container_size (v.size ());
7395 o.type = msgpack::type::BIN;
74- char * ptr = static_cast <char *>(o.zone .allocate_align (size));
75- o.via .bin .ptr = ptr;
7696 o.via .bin .size = size;
77- std::memcpy (ptr, &v.front (), size);
97+ if (size != 0 ) {
98+ char * ptr = static_cast <char *>(o.zone .allocate_align (size));
99+ o.via .bin .ptr = ptr;
100+ std::memcpy (ptr, &v.front (), size);
101+ }
78102 }
79103};
80104
0 commit comments