I have a function foo(const std::string& str); that it does crash if you call it using foo(NULL).
foo(const std::string& str);
foo(NULL)
What can I do to prevent it from cras
You have a function that accepts a std::string, so provide it an std::string, not a pointer.
std::string
foo(std::string());
This will provide the function with an empty string, which is probably what you would have interpreted your null value as anyhow.