Always allocate zt in output of SDL_iconv_string()

Before this, the function could not be used on buffers,
as it would not account for the zero-termination unless
it was included in the input.
This commit is contained in:
Eddy Jansson
2023-02-28 17:50:26 +01:00
committed by Sam Lantinga
parent 5fb5586233
commit 5f5abb6805
2 changed files with 4 additions and 3 deletions

View File

@@ -808,7 +808,7 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
}
stringsize = inbytesleft > 4 ? inbytesleft : 4;
string = (char *)SDL_malloc(stringsize);
string = (char *)SDL_malloc(stringsize + 1);
if (string == NULL) {
SDL_iconv_close(cd);
return NULL;
@@ -825,7 +825,7 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
{
char *oldstring = string;
stringsize *= 2;
string = (char *)SDL_realloc(string, stringsize);
string = (char *)SDL_realloc(string, stringsize + 1);
if (string == NULL) {
SDL_free(oldstring);
SDL_iconv_close(cd);
@@ -851,6 +851,7 @@ SDL_iconv_string(const char *tocode, const char *fromcode, const char *inbuf,
break;
}
}
*outbuf = '\0';
SDL_iconv_close(cd);
return string;