}
void Serialize(const char *t) {
- m_stream << t;
- m_stream.write(0x0);
+ const size_t size = t ? strlen(t) : std::numeric_limits<size_t>::max();
+ Serialize(size);
+ if (t) {
+ m_stream << t;
+ m_stream.write(0x0);
+ }
}
void Serialize(const char **t) {
Serialize(size);
// Serialize the content of the array.
- while (*t) {
- m_stream << *t;
- m_stream.write(0x0);
- ++t;
- }
+ while (*t)
+ Serialize(*t++);
}
/// Serialization stream.
}
template <> const char *Deserializer::Deserialize<const char *>() {
- auto pos = m_buffer.find('\0');
- if (pos == llvm::StringRef::npos)
+ const size_t size = Deserialize<size_t>();
+ if (size == std::numeric_limits<size_t>::max())
return nullptr;
+ assert(HasData(size + 1));
const char *str = m_buffer.data();
- m_buffer = m_buffer.drop_front(pos + 1);
+ m_buffer = m_buffer.drop_front(size + 1);
#ifdef LLDB_REPRO_INSTR_TRACE
llvm::errs() << "Deserializing with " << LLVM_PRETTY_FUNCTION << " -> \""
<< str << "\"\n";
}
template <> const char **Deserializer::Deserialize<const char **>() {
- size_t size = Deserialize<size_t>();
+ const size_t size = Deserialize<size_t>();
if (size == 0)
return nullptr;
const char **r =
EXPECT_STREQ(cstr, deserializer.Deserialize<const char *>());
}
+TEST(SerializationRountripTest, SerializeDeserializeCStringNull) {
+ const char *cstr = nullptr;
+
+ std::string str;
+ llvm::raw_string_ostream os(str);
+
+ Serializer serializer(os);
+ serializer.SerializeAll(cstr);
+
+ llvm::StringRef buffer(os.str());
+ Deserializer deserializer(buffer);
+
+ EXPECT_EQ(nullptr, deserializer.Deserialize<const char *>());
+}
+
TEST(SerializationRountripTest, SerializeDeserializeCStringArray) {
const char *foo = "foo";
const char *bar = "bar";