I have the following message definition
syntax = "proto3";
message TestMessage {
fixed32 id = 1;
bytes data = 2;
}
When I run the following program in DEBUG mode, I get an access violation.
#include <cstdint>
#include "test.pb.h"
int main(int argc, char *argv[])
{
TestMessage msg;
msg.set_id(4711);
std::string* dataString = msg.mutable_data();
dataString->resize(100000); // access violation here
std::cout << (*dataString) << std::endl;
std::string str;
std::getline(std::cin, str);
}
Even the following throws an access violation in DEBUG mode.
#include <cstdint>
#include "test.pb.h"
int main(int argc, char *argv[])
{
TestMessage msg;
msg.set_id(4711);
std::string* dataString = msg.mutable_data();
dataString->append("Hello, World!");
dataString->append("Hello, World!");
dataString->append("Hello, World!"); // access violation here
dataString->append("Hello, World!");
std::cout << (*dataString) << std::endl;
std::string str;
std::getline(std::cin, str);
}
In RELEASE mode the programs work as expected.
It’s annoying, as I cannot test my real app in DEBUG mode.
Any ideas what the problem is?
(Environment: Windows 10, Protocol Buffers v3.6.1, VS 2017, via cmake)
(#define PROTOBUF_USE_DLLS added to test.pb.h)
EDIT:
I tried again with static linked libs instead of dymanic linked, and than it works also in DEBUG mode.