[lldb/Reproducers] (De)serialize char* like const char*
authorJonas Devlieghere <jonas@devlieghere.com>
Wed, 5 Feb 2020 17:53:10 +0000 (09:53 -0800)
committerJonas Devlieghere <jonas@devlieghere.com>
Wed, 5 Feb 2020 22:52:08 +0000 (14:52 -0800)
The current implementation has a discrepancy between how char pointers
are serialized and deserialized. The latter treats it like a const char*
while the former serializes it as a pointer to a basic type.

Both are potentially wrong, as char pointers are mostly used in
combination with a size, and nothing guarantees that the string's length
(its first null byte to be more precise) is greater or equal to its
size. The real solution is to have a custom (de)serializer that uses
both pieces of infromation.

However, the implementation should be consistent between serialization
and deserialization and I believe treating char* as const char* is the
better alternative.

lldb/include/lldb/Utility/ReproducerInstrumentation.h

index 9039a7f..bc28999 100644 (file)
@@ -621,6 +621,8 @@ private:
     }
   }
 
+  void Serialize(char *t) { Serialize(static_cast<const char *>(t)); }
+
   void Serialize(const char **t) {
     size_t size = 0;
     if (!t) {