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

util.h defines _snprintf as snprintf on windows #696

Open
nico opened this issue Dec 21, 2013 · 3 comments
Open

util.h defines _snprintf as snprintf on windows #696

nico opened this issue Dec 21, 2013 · 3 comments
Labels

Comments

@nico
Copy link
Collaborator

nico commented Dec 21, 2013

http://randomascii.wordpress.com/2013/04/03/stop-using-strncpy-already/ :

// Make snprintf available on Windows:
// Don’t ever do this! These two functions are different!
#define snprintf _snprintf

(the former 0-terminates if the printed string is larger than the size, the latter doesn't.)

Audit calls to snprintf, check lack of 0-termination isn't an issue, then either have a portable wrapper around _snprintf on windows (that writes 0 in the last entry always), or something else.

@evmar
Copy link
Collaborator

evmar commented Dec 24, 2013

I think I was avoiding making a std::string StringPrintf(...) function just out of laziness. I am pretty sure we're not using format strings in any place where perf critical where we care about extra allocs or whatever.

(My new favorite trick to use, instead of sprintf(buf, "%s:%d blah", x, y), is instead std::string Fmt(const char* fmt, Arg arg1=Arg::None, Arg arg2=Arg::None) which is used like Fmt("$:$ blah", x, y) and Arg has implicit ctors for the various types you care about. Not that Ninja needs this.)

@nico
Copy link
Collaborator Author

nico commented Dec 19, 2014

A simple fix might be to #define snprintf _snprintf_s instead (?)

@evmar
Copy link
Collaborator

evmar commented Dec 19, 2014

We could just remove the one caller too:

https://github.com/martine/ninja/search?utf8=%E2%9C%93&q=strncpy

brevity due to phone
On Dec 19, 2014 11:50 AM, "Nico Weber" [email protected] wrote:

A simple fix might be to #define snprintf _snprintf_s instead (?)


Reply to this email directly or view it on GitHub
#696 (comment).

@jhasse jhasse added the windows label Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants