memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.13k stars 768 forks source link

Fix unsafe code #237

Open Gerharddc opened 9 years ago

Gerharddc commented 9 years ago

Visual Studio is complaining that some code like fopen is unsafe and deprecated claiming that fopen_s would be better. I can see that an attempt has been made to disable the warning but unfortunately it is still a lot of effort to really get it disabled. Is there any reason why the "unsafe" code has not been replaced with "safe" code yet?

memononen commented 9 years ago

fopen_sonly works on VS, not portable, and generally I don't see how it would be any safer than fopen.

Gerharddc commented 9 years ago

@memononen Ok, I didn't realize that. Would it be fine if I just added "safe" versions as conditional code for VS because it seems that VS feels very strongly about this?

Gerharddc commented 9 years ago

@memononen It seems that it actually became standard with C++11, or am I mistaken?

Hockenberry commented 9 years ago

fopen_s is not part of any "official" c/c++ standard. It is Microsoft CRT only! See https://msdn.microsoft.com/en-us/library/8ef0s5kh.aspx.

The definition of _CRT_SECURE_NO_WARNINGS for source files disables these functions and "removes" them from the headers.

Gerharddc commented 9 years ago

@Hockenberry I have actually found it easiest to just disable the "STL checks" in the properties of the source file in VS. I don't see that the MSDN article points out that the functions are MS only. What I have found though is that according to http://en.cppreference.com/w/c/io/fopen fopen_s was introduced into ISO C++ as of C++11 with their references pointing towards :

C11 standard (ISO/IEC 9899:2011):

7.21.5.3 The fopen function (p: 305-306)

K.3.5.2.1 The fopen_s function (p: 588-590)

If memory serves me correct though, support for C++11 has to be enabled by using a flag on GCC and is not supported by default even though GCC has support for C++11. As far as I know, most modern compilers have support for C++11 with many already having support for some of the proposed C++17 features.