Recently I met a bug when I was using google protobuf to serialize and deserialize messages.I have a code segment like this:
1 2 3 4 5 6 |
class MyMessage; // A message class generated by protobuf</code> void process() { MyMessage msg; std::string msg_buffer = some_other_func(); // receive binary format "string" msg.ParseFromString(msg_buffer.data()); } |
In the code, there is a weird usage of std::string::data() and MyMessage::ParseFromString() API. It’s a mistake due