Skip to content

Commit

Permalink
stdlib: just cast iconv()'s 2nd arg to void *.
Browse files Browse the repository at this point in the history
This makes the compiler happy (enough) regardless of whether the C runtime
headers think this argument should be const or not.

Fixes #4966.
  • Loading branch information
icculus committed Mar 22, 2022
1 parent 4b8d69a commit 8df045c
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions src/stdlib/SDL_iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,6 @@
#define LIBICONV_PLUG 1
#endif
#include <iconv.h>

/* 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 <errno.h>

SDL_COMPILE_TIME_ASSERT(iconv_t, sizeof (iconv_t) <= sizeof (SDL_iconv_t));
Expand All @@ -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:
Expand Down

0 comments on commit 8df045c

Please sign in to comment.