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.

(cherry picked from commit 5f5abb6805)
This commit is contained in:
Eddy Jansson authored and Sam Lantinga committed 2023-06-04 05:17:15 -07:00
1 parent 7c86d96e86
commit 2660da6f5c
2 files changed
+4 -3

No files matched your search

+3 -2
View File
@@ -811,7 +811,7 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
}
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;
@@ -828,7 +828,7 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
{
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);
@@ -855,6 +855,7 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
break;
}
}
*outbuf = '\0';
SDL_iconv_close(cd);
return string;