From 2a1d67eada999b249d81a0485f2fef286fdf78cb Mon Sep 17 00:00:00 2001 From: Jonathan Goyvaerts Date: Thu, 18 Apr 2019 00:09:40 +0200 Subject: [PATCH] [Base] Fix snprintf not working correctly This seems to be an issue with Microsoft declaring a snprintf macro which causes issues. Related issues: - https://github.com/nlohmann/json/issues/1408 - https://github.com/kodi-pvr/pvr.vuplus/issues/162 --- src/xenia/base/string_util.h | 13 ++++++------- src/xenia/base/vec128.h | 4 ++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/xenia/base/string_util.h b/src/xenia/base/string_util.h index 38bb85028..9b03527f2 100644 --- a/src/xenia/base/string_util.h +++ b/src/xenia/base/string_util.h @@ -24,13 +24,13 @@ namespace string_util { inline std::string to_hex_string(uint32_t value) { char buffer[21]; - std::snprintf(buffer, sizeof(buffer), "%08" PRIX32, value); + snprintf(buffer, sizeof(buffer), "%08" PRIX32, value); return std::string(buffer); } inline std::string to_hex_string(uint64_t value) { char buffer[21]; - std::snprintf(buffer, sizeof(buffer), "%016" PRIX64, value); + snprintf(buffer, sizeof(buffer), "%016" PRIX64, value); return std::string(buffer); } @@ -54,8 +54,8 @@ inline std::string to_hex_string(double value) { inline std::string to_hex_string(const vec128_t& value) { char buffer[128]; - std::snprintf(buffer, sizeof(buffer), "[%.8X, %.8X, %.8X, %.8X]", - value.u32[0], value.u32[1], value.u32[2], value.u32[3]); + snprintf(buffer, sizeof(buffer), "[%.8X, %.8X, %.8X, %.8X]", value.u32[0], + value.u32[1], value.u32[2], value.u32[3]); return std::string(buffer); } @@ -66,7 +66,7 @@ inline std::string to_hex_string(const __m128& value) { char buffer[128]; float f[4]; _mm_storeu_ps(f, value); - std::snprintf( + snprintf( buffer, sizeof(buffer), "[%.8X, %.8X, %.8X, %.8X]", *reinterpret_cast(&f[0]), *reinterpret_cast(&f[1]), *reinterpret_cast(&f[2]), *reinterpret_cast(&f[3])); @@ -77,8 +77,7 @@ inline std::string to_string(const __m128& value) { char buffer[128]; float f[4]; _mm_storeu_ps(f, value); - std::snprintf(buffer, sizeof(buffer), "(%F, %F, %F, %F)", f[0], f[1], f[2], - f[3]); + snprintf(buffer, sizeof(buffer), "(%F, %F, %F, %F)", f[0], f[1], f[2], f[3]); return std::string(buffer); } diff --git a/src/xenia/base/vec128.h b/src/xenia/base/vec128.h index 68d06744a..8779ade80 100644 --- a/src/xenia/base/vec128.h +++ b/src/xenia/base/vec128.h @@ -266,8 +266,8 @@ static inline vec128_t vec128b(uint8_t x0, uint8_t x1, uint8_t x2, uint8_t x3, inline std::string to_string(const vec128_t& value) { char buffer[128]; - std::snprintf(buffer, sizeof(buffer), "(%g, %g, %g, %g)", value.x, value.y, - value.z, value.w); + snprintf(buffer, sizeof(buffer), "(%g, %g, %g, %g)", value.x, value.y, + value.z, value.w); return std::string(buffer); }