Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/KhronosGroup/SPIRV-Cross.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans-Kristian Arntzen <post@arntzen-software.no>2022-06-23 15:30:12 +0300
committerGitHub <noreply@github.com>2022-06-23 15:30:12 +0300
commite6925974d1ff5cb6b6472b20eed380889cde2ae8 (patch)
treebb83f75528ea60c744f8141b943f3d078020caef
parentba3e6ffe037e47a17dd233a2e50eb0c0a434bb25 (diff)
parent9c44a97faa95bf1f11c31be0a4f35fc211b4707e (diff)
Merge pull request #1966 from fred-wang/macos-snprintf
Fix compilation errors with deprecated sprintf function
-rw-r--r--spirv_glsl.cpp13
-rw-r--r--spirv_msl.cpp14
2 files changed, 25 insertions, 2 deletions
diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp
index 80d40c0d..25e94700 100644
--- a/spirv_glsl.cpp
+++ b/spirv_glsl.cpp
@@ -5214,8 +5214,8 @@ string CompilerGLSL::constant_expression(const SPIRConstant &c, bool inside_bloc
}
#ifdef _MSC_VER
-// sprintf warning.
-// We cannot rely on snprintf existing because, ..., MSVC.
+// snprintf does not exist or is buggy on older MSVC versions, some of them
+// being used by MinGW. Use sprintf instead and disable corresponding warning.
#pragma warning(push)
#pragma warning(disable : 4996)
#endif
@@ -5275,7 +5275,11 @@ string CompilerGLSL::convert_float_to_string(const SPIRConstant &c, uint32_t col
in_type.width = 32;
char print_buffer[32];
+#ifdef _WIN32
sprintf(print_buffer, "0x%xu", c.scalar(col, row));
+#else
+ snprintf(print_buffer, sizeof(print_buffer), "0x%xu", c.scalar(col, row));
+#endif
const char *comment = "inf";
if (float_value == -numeric_limits<float>::infinity())
@@ -5347,8 +5351,13 @@ std::string CompilerGLSL::convert_double_to_string(const SPIRConstant &c, uint32
require_extension_internal("GL_ARB_gpu_shader_int64");
char print_buffer[64];
+#ifdef _WIN32
sprintf(print_buffer, "0x%llx%s", static_cast<unsigned long long>(u64_value),
backend.long_long_literal_suffix ? "ull" : "ul");
+#else
+ snprintf(print_buffer, sizeof(print_buffer), "0x%llx%s", static_cast<unsigned long long>(u64_value),
+ backend.long_long_literal_suffix ? "ull" : "ul");
+#endif
const char *comment = "inf";
if (double_value == -numeric_limits<double>::infinity())
diff --git a/spirv_msl.cpp b/spirv_msl.cpp
index 4687742b..7ce27018 100644
--- a/spirv_msl.cpp
+++ b/spirv_msl.cpp
@@ -16405,6 +16405,20 @@ void CompilerMSL::emit_block_hints(const SPIRBlock &)
string CompilerMSL::additional_fixed_sample_mask_str() const
{
char print_buffer[32];
+#ifdef _MSC_VER
+ // snprintf does not exist or is buggy on older MSVC versions, some of
+ // them being used by MinGW. Use sprintf instead and disable
+ // corresponding warning.
+#pragma warning(push)
+#pragma warning(disable : 4996)
+#endif
+#if _WIN32
sprintf(print_buffer, "0x%x", msl_options.additional_fixed_sample_mask);
+#else
+ snprintf(print_buffer, sizeof(print_buffer), "0x%x", msl_options.additional_fixed_sample_mask);
+#endif
+#ifdef _MSC_VER
+#pragma warning(pop)
+#endif
return print_buffer;
}