Skip to content

Commit d04b1e7

Browse files
authored
Fix empty string deserialization with API version 1
1 parent 0fddfe8 commit d04b1e7

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

include/msgpack/v1/adaptor/string.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,10 @@ struct convert<std::string> {
3030
msgpack::object const& operator()(msgpack::object const& o, std::string& v) const {
3131
switch (o.type) {
3232
case msgpack::type::BIN:
33-
if (o.via.bin.size == 0)
34-
v.clear();
35-
else
36-
v.assign(o.via.bin.ptr, o.via.bin.size);
33+
v.assign(o.via.bin.ptr, o.via.bin.size);
3734
break;
3835
case msgpack::type::STR:
39-
if (o.via.str.size == 0)
40-
v.clear();
41-
else
42-
v.assign(o.via.str.ptr, o.via.str.size);
36+
v.assign(o.via.str.ptr, o.via.str.size);
4337
break;
4438
default:
4539
throw msgpack::type_error();

include/msgpack/v1/unpack.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ inline void unpack_str(unpack_user& u, const char* p, uint32_t l, msgpack::objec
177177
std::memcpy(tmp, p, l);
178178
o.via.str.ptr = tmp;
179179
}
180+
else {
181+
o.via.str.ptr = MSGPACK_NULLPTR;
182+
}
180183
o.via.str.size = l;
181184
}
182185

@@ -193,6 +196,9 @@ inline void unpack_bin(unpack_user& u, const char* p, uint32_t l, msgpack::objec
193196
std::memcpy(tmp, p, l);
194197
o.via.bin.ptr = tmp;
195198
}
199+
else {
200+
o.via.bin.ptr = MSGPACK_NULLPTR;
201+
}
196202
o.via.bin.size = l;
197203
}
198204

0 commit comments

Comments
 (0)