Change PUGI__SNPRINTF to use _countof for MSVC

The macro only works correctly when the input argument is an array with
a statically known size - pointers or arrays decayed to pointers won't
work silently.

While this is unlikely to surface issues that aren't caught in
tests/code review, use _countof for MSVC to prevent such code from
compiling.
This commit is contained in:
Arseny Kapoulkine 2017-06-19 07:06:47 -07:00
parent 867bd2583b
commit 208e2cf043

View File

@ -131,7 +131,7 @@ using std::memset;
#if __cplusplus >= 201103
# define PUGI__SNPRINTF(buf, ...) snprintf(buf, sizeof(buf), __VA_ARGS__)
#elif defined(_MSC_VER) && _MSC_VER >= 1400
# define PUGI__SNPRINTF(buf, ...) _snprintf_s(buf, sizeof(buf), _TRUNCATE, __VA_ARGS__)
# define PUGI__SNPRINTF(buf, ...) _snprintf_s(buf, _countof(buf), _TRUNCATE, __VA_ARGS__)
#else
# define PUGI__SNPRINTF sprintf
#endif