GithubHelp home page GithubHelp logo

strncpy error in VS2013 about inih HOT 9 CLOSED

benhoyt avatar benhoyt commented on August 17, 2024
strncpy error in VS2013

from inih.

Comments (9)

benhoyt avatar benhoyt commented on August 17, 2024

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?

from inih.

AgostinoSturaro avatar AgostinoSturaro commented on August 17, 2024

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.

from inih.

andravin avatar andravin commented on August 17, 2024

@benhoyt yes, and identify windows with #ifdef _WIN32

from inih.

cremno avatar cremno commented on August 17, 2024

@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.

from inih.

andravin avatar andravin commented on August 17, 2024

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.

from inih.

cremno avatar cremno commented on August 17, 2024

@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

from inih.

benhoyt avatar benhoyt commented on August 17, 2024

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

from inih.

benhoyt avatar benhoyt commented on August 17, 2024

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.

from inih.

benhoyt avatar benhoyt commented on August 17, 2024

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

from inih.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.