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

Fix sprintf issue on MacOS for non-XCode compilers #1510

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stephanlachnit
Copy link
Contributor

@stephanlachnit stephanlachnit commented Jul 11, 2024

@chriskohlhoff @klemens-morgenstern

This should fix the sprintf issue on MacOS for good, in particular if XCode is not used but e.g. clang from brew (see #1148 for discussion).

The issue is the check of ASIO_HAS_SNPRINTF here:

// Standard library support for snprintf.
#if !defined(ASIO_HAS_SNPRINTF)
# if !defined(ASIO_DISABLE_SNPRINTF)
# if defined(__apple_build_version__)
# if (__clang_major__ >= 14)
# define ASIO_HAS_SNPRINTF 1
# endif // (__clang_major__ >= 14)
# endif // defined(__apple_build_version__)
# endif // !defined(ASIO_DISABLE_SNPRINTF)
#endif // !defined(ASIO_HAS_SNPRINTF)

It only checks if __apple_build_version__ is defined, however this variable isn't set when using non-XCode compilers on MacOS. Since snprintf is available in MacOS since version 10.0, which was released in March 2001, is think the best option is to always set ASIO_HAS_SNPRINTF if __APPLE__ is detected.

Note that is also fixes a missing instance where sprintf_s can be used via Microsoft RTL.

Closes #1148 closes #1449 closes #1183

Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
__apple_build_version__ only works for XCode, but not e.g. for clang installed from brew.

snprintf has been added in MacOS 10.0, which was released in March 2001.

Signed-off-by: Stephan Lachnit <stephanlachnit@debian.org>
@stephanlachnit stephanlachnit changed the title Fix sprintf issue on MacOS for good Fix sprintf issue on MacOS for non-XCode compilers Jul 11, 2024
@stephanlachnit
Copy link
Contributor Author

@chriskohlhoff can we get this merged? This is really annoying on MacOS with non-apple clang and a very simple fix.

@klemens-morgenstern
Copy link
Contributor

Why can't you just define ASIO_HAS_SNPRINTF ?

@stephanlachnit
Copy link
Contributor Author

Why can't you just define ASIO_HAS_SNPRINTF ?

Cause it is deprecated and the default should not emit a warning. And the Apple workaround only checks for Apple clang, while it should really check for the Apple C library, which is also used by upstream clang.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants