Skip to content

Commit

Permalink
SDL: Use a non-const string for SDL_iconv_string
Browse files Browse the repository at this point in the history
With some older versions of SDL1, the SDL_iconv_string takes
char * instead of const char * as it's argument. This should
fix the build issue with gp2xwiz.
  • Loading branch information
vyzigold authored and David Turner committed Aug 24, 2019
1 parent fb54cc1 commit c2e0e90
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions backends/platform/sdl/sdl.cpp
Expand Up @@ -774,6 +774,17 @@ char *OSystem_SDL::convertEncoding(const char *to, const char *from, const char
zeroBytes = 2;
if (Common::String(from).hasPrefixIgnoreCase("utf-32"))
zeroBytes = 4;

// SDL_iconv_string() takes char * instead of const char * as it's third parameter
// with some older versions of SDL.
#if SDL_VERSION_ATLEAST(2, 0, 0)
return SDL_iconv_string(to, from, string, length + zeroBytes);
#else
char *stringCopy = (char *) calloc(sizeof(char), length + zeroBytes);
memcpy(stringCopy, string, length);
char *result = SDL_iconv_string(to, from, stringCopy, length + zeroBytes);
free(stringCopy);
return result;
#endif
}

0 comments on commit c2e0e90

Please sign in to comment.