From dd678ea2321f93b5ef7ef7878394aef44e738651 Mon Sep 17 00:00:00 2001 From: neondev1 <82016241+neondev1@users.noreply.github.com> Date: Sun, 27 Oct 2024 00:03:07 -0700 Subject: [PATCH 1/3] stb_image_write: Fix error caused by sprintf on MSVC __STDC_LIB_EXT1__ is not defined on MSVC, causing line 766 to raise the following error: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. --- stb_image_write.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_image_write.h b/stb_image_write.h index e4b32ed1b..7a81f2a1a 100644 --- a/stb_image_write.h +++ b/stb_image_write.h @@ -770,7 +770,7 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n"; s->func(s->context, header, sizeof(header)-1); -#ifdef __STDC_LIB_EXT1__ +#if defined(_MSC_VER) && _MSC_VER >= 1400 len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #else len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); From 2f7f6db427a3fdc74c97ba1023577aff387525fd Mon Sep 17 00:00:00 2001 From: neondev1 <82016241+neondev1@users.noreply.github.com> Date: Sun, 27 Oct 2024 00:31:20 -0700 Subject: [PATCH 2/3] stb_image_write: Added call to snprintf Prevents some warnings --- stb_image_write.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stb_image_write.h b/stb_image_write.h index 7a81f2a1a..5f7353262 100644 --- a/stb_image_write.h +++ b/stb_image_write.h @@ -320,9 +320,9 @@ static FILE *stbiw__fopen(char const *filename, char const *mode) f = _wfopen(wFilename, wMode); #endif -#elif defined(_MSC_VER) && _MSC_VER >= 1400 +#elif (defined(_MSC_VER) && _MSC_VER >= 1400) if (0 != fopen_s(&f, filename, mode)) - f=0; + f = 0; #else f = fopen(filename, mode); #endif @@ -772,6 +772,8 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f #if defined(_MSC_VER) && _MSC_VER >= 1400 len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199001L + len = snprintf(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #else len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #endif From afa6fd064c75acadfd0ec243583e6a4a84c42b99 Mon Sep 17 00:00:00 2001 From: neondev1 <82016241+neondev1@users.noreply.github.com> Date: Sun, 27 Oct 2024 00:39:08 -0700 Subject: [PATCH 3/3] stb_image_write: Re-added __STDC_LIB_EXT1__ macros Not sure if this is wanted, but this will use the _s variants of functions where supported (C11) --- stb_image_write.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/stb_image_write.h b/stb_image_write.h index 5f7353262..6bab65ef2 100644 --- a/stb_image_write.h +++ b/stb_image_write.h @@ -313,14 +313,16 @@ static FILE *stbiw__fopen(char const *filename, char const *mode) if (0 == MultiByteToWideChar(65001 /* UTF8 */, 0, mode, -1, wMode, sizeof(wMode)/sizeof(*wMode))) return 0; -#if defined(_MSC_VER) && _MSC_VER >= 1400 +#if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ && defined(__STDC_LIB_EXT1__)) \ + || (defined(_MSC_VER) && _MSC_VER >= 1400) if (0 != _wfopen_s(&f, wFilename, wMode)) f = 0; #else f = _wfopen(wFilename, wMode); #endif -#elif (defined(_MSC_VER) && _MSC_VER >= 1400) +#elif (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ && defined(__STDC_LIB_EXT1__)) \ + || (defined(_MSC_VER) && _MSC_VER >= 1400) if (0 != fopen_s(&f, filename, mode)) f = 0; #else @@ -770,7 +772,8 @@ static int stbi_write_hdr_core(stbi__write_context *s, int x, int y, int comp, f char header[] = "#?RADIANCE\n# Written by stb_image_write.h\nFORMAT=32-bit_rle_rgbe\n"; s->func(s->context, header, sizeof(header)-1); -#if defined(_MSC_VER) && _MSC_VER >= 1400 +#if (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ && defined(__STDC_LIB_EXT1__)) \ + || (defined(_MSC_VER) && _MSC_VER >= 1400) len = sprintf_s(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x); #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199001L len = snprintf(buffer, sizeof(buffer), "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);