std::string s("foo");
sprintf(buf,"%s",s);
Why at least under MSVC 2010 this line of code doesn’t bug in DEBUG, but bug in RELEASE ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
%sformat specifier expects a NULL terminatedchar*. You are passing in astd::stringinstance. If it works in DEBUG, that’s just pure luck.You should use:
This will extract a
char*and ensure that the buffer is NULL terminated.It is possible that in the runtime library
std::stringhas different implementations for DEBUG and RELEASE. Try compiling using both settings, but adding debug symbols to the RELEASE build and then step through the code. Look at the memory location wheresis stored. Is there any difference?