Open nico opened 10 years ago
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.)
A simple fix might be to #define snprintf _snprintf_s
instead (?)
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" notifications@github.com wrote:
A simple fix might be to #define snprintf _snprintf_s instead (?)
— Reply to this email directly or view it on GitHub https://github.com/martine/ninja/issues/696#issuecomment-67687893.
http://randomascii.wordpress.com/2013/04/03/stop-using-strncpy-already/ :
(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.