I have this Rust function:
pub extern "C" fn do_something(my_string: &str) {
let s = String::from(my_string);
}
That I call on C++ with this:
std::string my_string("hello");
do_something(my_string.c_str());
Signature:
extern "C" void* do_something(const char*);
I get this error right on the String::from line:
memory allocation of 127963177044160 bytes failedAborted (core dumped)
I guess that it's because the string passed has no \n so it tries to make a string of the maximum size possible.
How to safely pass a std::string to Rust?