Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stb_image_write: Fix error caused by use of sprintf on MSVC #1712

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions stb_image_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,16 +313,18 @@ 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;
f = 0;
#else
f = fopen(filename, mode);
#endif
Expand Down Expand Up @@ -770,8 +772,11 @@ 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(__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);
#else
len = sprintf(buffer, "EXPOSURE= 1.0000000000000\n\n-Y %d +X %d\n", y, x);
#endif
Expand Down