chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.97k stars 1.22k forks source link

MSVC: getenv is unsafe #1554

Closed matbech closed 2 weeks ago

matbech commented 3 weeks ago

0007-disable warning.patch The MSVC compiler complains about getenv being unsafe.

asio\asio\include\asio\impl\config.ipp(304,17): error C4996: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

There are a couple of workarounds: https://stackoverflow.com/questions/66090389/c17-what-new-with-error-c4996-getenv-this-function-or-variable-may-be-un

I propose the following patch:

#if _MSC_VER >= 1200
#pragma warning(push)
#pragma warning(disable: 4996)
#endif
    return std::getenv(env_var.c_str());
#if _MSC_VER >= 1200
#pragma warning(pop)
#endif
matbech commented 2 weeks ago

This has been addressed in commit: https://github.com/chriskohlhoff/asio/commit/aae3cd191742d16527615a024eac3818625e762e