Util: Fix realloc semantics in utf16to8 (again)
Jeffrey Pfau jeffrey@endrift.com
Fri, 29 Jul 2016 21:27:47 -0700
1 files changed,
3 insertions(+),
4 deletions(-)
jump to
M
src/util/string.c
→
src/util/string.c
@@ -187,12 +187,11 @@ utf8TotalBytes = 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) { + offset = o + newUTF8; + if (!newUTF8) { free(utf8); - } - if (!newUTF8) { return 0; } utf8 = newUTF8;