Util: Fix realloc semantics in utf16to8 (again)

This commit is contained in:
Jeffrey Pfau 2016-07-29 21:27:47 -07:00
parent f4e26656e4
commit 8862dc49aa
1 changed files with 3 additions and 4 deletions

View File

@ -187,12 +187,11 @@ char* utf16to8(const uint16_t* utf16, size_t length) {
memcpy(utf8, buffer, bytes);
offset = utf8 + bytes;
} else if (utf8Length >= utf8TotalBytes) {
ptrdiff_t o = offset - utf8;
char* newUTF8 = realloc(utf8, utf8TotalBytes * 2);
offset = offset - utf8 + newUTF8;
if (newUTF8 != utf8) {
free(utf8);
}
offset = o + newUTF8;
if (!newUTF8) {
free(utf8);
return 0;
}
utf8 = newUTF8;