diff --git a/src/util/string.c b/src/util/string.c index 08e4a4292..0157d4403 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -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;