all repos — mgba @ 8862dc49aa03691b5cbd614dde1a99420d555cbd

mGBA Game Boy Advance Emulator

Util: Fix realloc semantics in utf16to8 (again)
Jeffrey Pfau jeffrey@endrift.com
Fri, 29 Jul 2016 21:27:47 -0700
commit

8862dc49aa03691b5cbd614dde1a99420d555cbd

parent

f4e26656e4425f7cc83bedb7cc7aa15ca5e6e0b0

1 files changed, 3 insertions(+), 4 deletions(-)

jump to
M src/util/string.csrc/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;