]> The Tcpdump Group git mirrors - tcpdump/commit
Fix nd_snprintf(buf, buflen, "string");
authorGuy Harris <[email protected]>
Sun, 14 Oct 2018 05:51:54 +0000 (22:51 -0700)
committerGuy Harris <[email protected]>
Sun, 14 Oct 2018 05:51:54 +0000 (22:51 -0700)
commit1c30d69b979624733af5cbd2dd9653b609584e6f
tree26867f0671d942f76fe00e8efb159f1362f4bdb4
parentf3c200c36c1ae7ccc97dfbafd1599467d4ebb154
Fix nd_snprintf(buf, buflen, "string");

If this is VS prior to 2015 or MinGW, we can't trust snprintf(); we have
to use _snprintf_s(), but that requires us to insert _TRUNCATE as an
argument after the buffer and buffer length and before the format string
and arguments, if any, to the format string.

That means we need to use a vararg macro; however, if we make the format
string a regular argument to the macro, that means that, if there are no
arguments *after* the format string, you end up with an argument list to
_snprintf_s() that ends with "fmt, ", and that's not valid C.

*If* we knew this was GCC or Clang, we could use a GNU C-specific hack,
wherein, if __VA_ARGS__ is preceded by ## and there's a comma before
that, the comma is removed if __VA_ARGS__ is empty, but this might be
Microsoft's C compiler in a version of Visual Studio prior to VS 2015,
which might not support that.

So we have to just have the macro take, as the ... arguments, the format
string and its arguments.

Addresses GitHub issue #713.
netdissect-stdinc.h