From 208e2cf0432a0f2865a225a9dc51917191c6cd04 Mon Sep 17 00:00:00 2001 From: Arseny Kapoulkine Date: Mon, 19 Jun 2017 07:06:47 -0700 Subject: 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. --- src/pugixml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pugixml.cpp b/src/pugixml.cpp index 4bc971b..e047822 100644 --- a/src/pugixml.cpp +++ b/src/pugixml.cpp @@ -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 -- cgit v1.2.3