Skip to content
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

strncpy error in VS2013 #34

Closed
AgostinoSturaro opened this issue Mar 21, 2015 · 9 comments
Closed

strncpy error in VS2013 #34

AgostinoSturaro opened this issue Mar 21, 2015 · 9 comments

Comments

@AgostinoSturaro
Copy link

This library seems promising, with tests and all.

When I tried your example in Visual Studio 2013, I got this error

Error   1   error C4996: 'strncpy': This function or variable may be unsafe. Consider using strncpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.    c:\users\sturaroa\downloads\inih-r30\ini.c  56  1   IniParserTest

I'd rather not use have to set permissive flags just for this bit.

@benhoyt
Copy link
Owner

benhoyt commented Mar 21, 2015

Hmm, interesting. I believe my use of strncpy here is actually safe. What's the typical solution for this? #if to check if you're compiling on Windows, and use strncpy_s or something if so, otherwise regular strncpy?

@AgostinoSturaro
Copy link
Author

I've researched this, it seems to be VS2013 (and VS2012) complaining about simple things like fopen as well, suggesting to use the _s versions defined in TR 24731, which is an optional extension of C11.
There's this option to silence it without raising the _CRT_SECURE_NO_WARNINGS flag everywhere.

BTW I'm using the cpp wrapper. What happens if the ini file is malformed? Can I detect that with reader.ParseError() right after having initialized the reader with INIReader reader("path")?

Thanks.

@andravin
Copy link

andravin commented Apr 6, 2015

@benhoyt yes, and identify windows with #ifdef _WIN32

@cremno
Copy link

cremno commented Apr 13, 2015

@benhoyt: Yes, it's safe here. A solution could be for users to define _CRT_SECURE_NO_WARNINGS (with /D or #define) by themselves. You could also do it for them.

@AgostinoSturaro: You're mistaken. MS doesn't implement those C11 functions (yet). There are many differences between them.

@andravin: This has nothing to do with Windows itself. There are also other C compilers and standard libraries for Windows.

@andravin
Copy link

OK, if the strncpy warning is MSVC only, then instead of checking for MS Windows with #ifdef _WIN32, you can check for the MSVC compiler using #ifdef _MSC_VER

I don't think requiring the user to define _CRT_SECURE_NO_WARNINGS is an acceptable solution.

@cremno
Copy link

cremno commented Apr 13, 2015

@andravin:

You could also do it for them.

That's only one line (#define _CRT_SECURE_NO_WARNINGS) he has to add before the #include directives in ini.c

@benhoyt
Copy link
Owner

benhoyt commented Apr 13, 2015

Okay, I'm happy to add this to ini.c -- I'll do this in the next few days:

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS 1
#endif

@benhoyt
Copy link
Owner

benhoyt commented Apr 14, 2015

I don't have ready access to MSVC right now -- can someone please try adding the above #ifdef dance before the #includes in ini.c and ensure the warning goes away? If so, feel free to send a pull request.

@benhoyt
Copy link
Owner

benhoyt commented Apr 17, 2015

Fixed in c3458c9 and created release r31 with fix: https://github.com/benhoyt/inih/releases/tag/r31

@benhoyt benhoyt closed this as completed Apr 17, 2015
galaxy001 pushed a commit to galaxysd/GalaxyCodeBases that referenced this issue Dec 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants