From 8df045cc7d6ca21dd8ebbbe11ca24dfe81851f3b Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 22 Mar 2022 15:53:40 -0400 Subject: [PATCH] stdlib: just cast iconv()'s 2nd arg to void *. This makes the compiler happy (enough) regardless of whether the C runtime headers think this argument should be const or not. Fixes #4966. --- src/stdlib/SDL_iconv.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/stdlib/SDL_iconv.c b/src/stdlib/SDL_iconv.c index c88731b8d..3f5c82745 100644 --- a/src/stdlib/SDL_iconv.c +++ b/src/stdlib/SDL_iconv.c @@ -36,18 +36,6 @@ #define LIBICONV_PLUG 1 #endif #include - -/* Depending on which standard the iconv() was implemented with, - iconv() may or may not use const char ** for the inbuf param. - If we get this wrong, it's just a warning, so no big deal. -*/ -#if defined(_XGP6) || defined(__APPLE__) || defined(__RISCOS__) || defined(__FREEBSD__) || \ - defined(__EMSCRIPTEN__) || \ - (defined(__GLIBC__) && ((__GLIBC__ > 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2)) || \ - (defined(_NEWLIB_VERSION))) -#define ICONV_INBUF_NONCONST -#endif - #include SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t)); @@ -69,12 +57,9 @@ SDL_iconv(SDL_iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft) { - size_t retCode; -#ifdef ICONV_INBUF_NONCONST - retCode = iconv((iconv_t) ((uintptr_t) cd), (char **) inbuf, inbytesleft, outbuf, outbytesleft); -#else - retCode = iconv((iconv_t) ((uintptr_t) cd), inbuf, inbytesleft, outbuf, outbytesleft); -#endif + /* iconv's second parameter may or may not be `const char const *` depending on the + C runtime's whims. Casting to void * seems to make everyone happy, though. */ + const size_t retCode = iconv((iconv_t) ((uintptr_t) cd), (void *) inbuf, inbytesleft, outbuf, outbytesleft); if (retCode == (size_t) - 1) { switch (errno) { case E2BIG: