summaryrefslogtreecommitdiff
path: root/netdissect-stdinc.h
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-10-13 22:51:54 -0700
committerGuy Harris <guy@alum.mit.edu>2018-10-13 22:51:54 -0700
commit1c30d69b979624733af5cbd2dd9653b609584e6f (patch)
tree26867f0671d942f76fe00e8efb159f1362f4bdb4 /netdissect-stdinc.h
parentf3c200c36c1ae7ccc97dfbafd1599467d4ebb154 (diff)
downloadtcpdump-1c30d69b979624733af5cbd2dd9653b609584e6f.tar.gz
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.
Diffstat (limited to 'netdissect-stdinc.h')
-rw-r--r--netdissect-stdinc.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/netdissect-stdinc.h b/netdissect-stdinc.h
index 7bea0c4f..6455e8a6 100644
--- a/netdissect-stdinc.h
+++ b/netdissect-stdinc.h
@@ -328,8 +328,8 @@ typedef char* caddr_t;
* VS prior to 2015, or MingGW; assume we have _snprintf_s() and
* _vsnprintf_s(), which guarantee null termination.
*/
- #define nd_snprintf(buf, buflen, fmt, ...) \
- _snprintf_s(buf, buflen, _TRUNCATE, fmt, __VA_ARGS__)
+ #define nd_snprintf(buf, buflen, ...) \
+ _snprintf_s(buf, buflen, _TRUNCATE, __VA_ARGS__)
#define nd_vsnprintf(buf, buflen, fmt, ap) \
_vsnprintf_s(buf, buflen, _TRUNCATE, fmt, ap)
#endif /* defined(_MSC_VER) && _MSC_VER >= 1900 */