Do a full UCS4 zero termination on iconv converted strings
We don't necessarily know the size of the output characters, so do a full 32-bit zero termination on the output string. This fixes garbage at the end of Windows clipboard text
This commit is contained in:
@@ -801,15 +801,15 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
stringsize = inbytesleft > 4 ? inbytesleft : 4;
|
stringsize = inbytesleft;
|
||||||
string = (char *)SDL_malloc(stringsize + 1);
|
string = (char *)SDL_malloc(stringsize + sizeof(Uint32));
|
||||||
if (string == NULL) {
|
if (string == NULL) {
|
||||||
SDL_iconv_close(cd);
|
SDL_iconv_close(cd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
outbuf = string;
|
outbuf = string;
|
||||||
outbytesleft = stringsize;
|
outbytesleft = stringsize;
|
||||||
SDL_memset(outbuf, 0, 4);
|
SDL_memset(outbuf, 0, sizeof(Uint32));
|
||||||
|
|
||||||
while (inbytesleft > 0) {
|
while (inbytesleft > 0) {
|
||||||
const size_t oldinbytesleft = inbytesleft;
|
const size_t oldinbytesleft = inbytesleft;
|
||||||
@@ -819,7 +819,7 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
|
|||||||
{
|
{
|
||||||
char *oldstring = string;
|
char *oldstring = string;
|
||||||
stringsize *= 2;
|
stringsize *= 2;
|
||||||
string = (char *)SDL_realloc(string, stringsize + 1);
|
string = (char *)SDL_realloc(string, stringsize + sizeof(Uint32));
|
||||||
if (string == NULL) {
|
if (string == NULL) {
|
||||||
SDL_free(oldstring);
|
SDL_free(oldstring);
|
||||||
SDL_iconv_close(cd);
|
SDL_iconv_close(cd);
|
||||||
@@ -827,7 +827,7 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
|
|||||||
}
|
}
|
||||||
outbuf = string + (outbuf - oldstring);
|
outbuf = string + (outbuf - oldstring);
|
||||||
outbytesleft = stringsize - (outbuf - string);
|
outbytesleft = stringsize - (outbuf - string);
|
||||||
SDL_memset(outbuf, 0, 4);
|
SDL_memset(outbuf, 0, sizeof(Uint32));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case SDL_ICONV_EILSEQ:
|
case SDL_ICONV_EILSEQ:
|
||||||
@@ -846,7 +846,7 @@ char *SDL_iconv_string(const char *tocode, const char *fromcode, const char *inb
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*outbuf = '\0';
|
SDL_memset(outbuf, 0, sizeof(Uint32));
|
||||||
SDL_iconv_close(cd);
|
SDL_iconv_close(cd);
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
|
|||||||
Reference in New Issue
Block a user