-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C4996 error and warning with Visual Studio #463
Comments
Thanks for reporting! I had some headaches taking over the code with |
Since dealing with string here, In my opinion the There is only one usage of const auto data_end = m_buf.begin() + strlen(m_buf.data());
const bool value_is_int_like =
std::none_of(m_buf.begin(), data_end, [](const char c)
{
return (c == '.' or c == 'e' or c == 'E');
}); which then can be switched to |
The rationale for using |
Well both |
Another solution for the warnings #if defined(_MSC_VER)
#define JSON_STRCPY strcpy_s
#define JSON_STRCAT strcat_s
#define JSON_STROUT(out, buflen) out, buflen
#else
#define JSON_STRCPY std::strcpy
#define JSON_STRCAT std::strcat
#define JSON_STROUT(out, buflen) out
#endif Then call like this and finally #undef JSON_STRCAT
#undef JSON_STRCPY
#undef JSON_STROUT What do you think? |
I did some refactoring to avoid the unsafe calls, see 83a9c60. I combined a call to |
@prsyahmi Could you please try with the most recent version? |
The code looks good and it compiles fine here, no more warning and error 👍 I guess this can be closed now. Thanks! |
Using latest commit, C4996 errors and warnings spew on every string manipulation function calls:
std::strcpy
(Warning)std::strcat
(Warning)std::copy
(Error - compile fail) on non-iterator/pointer destinationError C4996 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
changing
std::copy(m_start, m_end, buf.data());
tostd::copy(m_start, m_end, buf.begin());
fix this problem.warning C4996: 'strcat': This function or variable may be unsafe. Consider using strcat_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS.
I think turning off the warning like proposed on #453 before might be enough but probably not a clean solution.
The text was updated successfully, but these errors were encountered: