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

Conversation

neondev1
Copy link

@neondev1 neondev1 commented Oct 27, 2024

__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.

I initially replaced the condition with defined(_MSC_VER) && _MSC_VER >= 1400 for the sake of consistency with the other two occurrences of _s functions in this file, but I later (in the third commit) replaced the conditions with (defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ && defined(__STDC_LIB_EXT1__)) || (defined(_MSC_VER) && _MSC_VER >= 1400) for all three locations where _s functions were called so that _s functions would be used over regular functions where supported; if the latter is unwanted, please feel free to remove it. A call to snprintf was also added for non-MSVC implementations supporting C99 but not _s functions.

The updated code compiles using GCC and MSVC on Windows as well as GCC and Clang on Ubuntu.

__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.
Not sure if this is wanted, but this will use the _s variants of functions where supported (C11)
@neondev1 neondev1 changed the title Fix error caused by use of sprintf on MSVC stb_image_write: Fix error caused by use of sprintf on MSVC Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant