From 8a32ee24dbb56f5ddfd047e608835bae928a420a Mon Sep 17 00:00:00 2001 From: Ozkan Sezer Date: Wed, 30 Dec 2020 01:00:24 +0300 Subject: [PATCH] removed MSVC strtok_s use from SDL_strtokr(). no other ??_s are used elsewhere in SDL_stdinc. besides, C11 has a strtok_s with a different signature. --- CMakeLists.txt | 2 +- include/SDL_config.h.cmake | 2 +- include/SDL_config.h.in | 1 - include/SDL_config_windows.h | 3 --- include/SDL_config_winrt.h | 14 +++++++------- src/stdlib/SDL_strtokr.c | 5 +---- 6 files changed, 10 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42a1a046d..1bda90d80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -780,7 +780,7 @@ if(LIBC) wcslen wcsdup wcsstr wcscmp wcsncmp _wcsicmp _wcsnicmp strlen _strrev _strupr _strlwr strchr strrchr strstr itoa _ltoa _ultoa strtol strtoul strtoll strtod atoi atof strcmp strncmp - _stricmp _strnicmp strtok_s sscanf + _stricmp _strnicmp sscanf acos acosf asin asinf atan atanf atan2 atan2f ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f lround lroundf pow powf round roundf scalbn scalbnf diff --git a/include/SDL_config.h.cmake b/include/SDL_config.h.cmake index f9b109049..615675dd9 100644 --- a/include/SDL_config.h.cmake +++ b/include/SDL_config.h.cmake @@ -116,7 +116,6 @@ #cmakedefine HAVE_STRRCHR 1 #cmakedefine HAVE_STRSTR 1 #cmakedefine HAVE_STRTOK_R 1 -#cmakedefine HAVE_STRTOK_S 1 #cmakedefine HAVE_ITOA 1 #cmakedefine HAVE__LTOA 1 #cmakedefine HAVE__UITOA 1 @@ -207,6 +206,7 @@ #cmakedefine HAVE_STDARG_H 1 #cmakedefine HAVE_STDDEF_H 1 #cmakedefine HAVE_FLOAT_H 1 + #else /* We may need some replacement for stdarg.h here */ #include diff --git a/include/SDL_config.h.in b/include/SDL_config.h.in index 88af73c75..1e9980fb1 100644 --- a/include/SDL_config.h.in +++ b/include/SDL_config.h.in @@ -119,7 +119,6 @@ #undef HAVE_STRRCHR #undef HAVE_STRSTR #undef HAVE_STRTOK_R -#undef HAVE_STRTOK_S #undef HAVE_ITOA #undef HAVE__LTOA #undef HAVE__UITOA diff --git a/include/SDL_config_windows.h b/include/SDL_config_windows.h index 0eaef9046..faaef72ec 100644 --- a/include/SDL_config_windows.h +++ b/include/SDL_config_windows.h @@ -119,9 +119,6 @@ typedef unsigned int uintptr_t; #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 /* #undef HAVE_STRTOK_R */ -#if defined(_MSC_VER) -#define HAVE_STRTOK_S 1 -#endif /* These functions have security warnings, so we won't use them */ /* #undef HAVE__LTOA */ /* #undef HAVE__ULTOA */ diff --git a/include/SDL_config_winrt.h b/include/SDL_config_winrt.h index a00185a32..6b40bc97c 100644 --- a/include/SDL_config_winrt.h +++ b/include/SDL_config_winrt.h @@ -126,17 +126,12 @@ typedef unsigned int uintptr_t; #define HAVE_STRLEN 1 #define HAVE__STRREV 1 #define HAVE__STRUPR 1 -//#define HAVE__STRLWR 1 // TODO, WinRT: consider using _strlwr_s instead #define HAVE_STRCHR 1 #define HAVE_STRRCHR 1 #define HAVE_STRSTR 1 -#define HAVE_STRTOK_S 1 -//#define HAVE_ITOA 1 // TODO, WinRT: consider using _itoa_s instead -//#define HAVE__LTOA 1 // TODO, WinRT: consider using _ltoa_s instead -//#define HAVE__ULTOA 1 // TODO, WinRT: consider using _ultoa_s instead #define HAVE_STRTOL 1 #define HAVE_STRTOUL 1 -//#define HAVE_STRTOLL 1 +/* #undef HAVE_STRTOLL */ #define HAVE_STRTOD 1 #define HAVE_ATOI 1 #define HAVE_ATOF 1 @@ -145,7 +140,12 @@ typedef unsigned int uintptr_t; #define HAVE__STRICMP 1 #define HAVE__STRNICMP 1 #define HAVE_VSNPRINTF 1 -//#define HAVE_SSCANF 1 // TODO, WinRT: consider using sscanf_s instead +/* TODO, WinRT: consider using ??_s versions of the following */ +/* #undef HAVE__STRLWR */ +/* #undef HAVE_ITOA */ +/* #undef HAVE__LTOA */ +/* #undef HAVE__ULTOA */ +/* #undef HAVE_SSCANF */ #define HAVE_M_PI 1 #define HAVE_ACOS 1 #define HAVE_ACOSF 1 diff --git a/src/stdlib/SDL_strtokr.c b/src/stdlib/SDL_strtokr.c index 3d69363ff..0a53dc392 100644 --- a/src/stdlib/SDL_strtokr.c +++ b/src/stdlib/SDL_strtokr.c @@ -28,12 +28,9 @@ char *SDL_strtokr(char *s1, const char *s2, char **ptr) { -#if defined(HAVE_STRTOK_R) +#ifdef HAVE_STRTOK_R return strtok_r(s1, s2, ptr); -#elif defined(_MSC_VER) && defined(HAVE_STRTOK_S) - return strtok_s(s1, s2, ptr); - #else /* SDL implementation */ /* * Adapted from _PDCLIB_strtok() of PDClib library at