From 590405d87824391e666b04020cb233dacfa6c4f6 Mon Sep 17 00:00:00 2001 From: Tsuda Kageyu Date: Wed, 23 Jul 2014 15:35:49 +0900 Subject: [PATCH] Fixed handling UTF-16 byte order. --- taglib/toolkit/tstring.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/taglib/toolkit/tstring.cpp b/taglib/toolkit/tstring.cpp index 603455a1..c43d70b6 100644 --- a/taglib/toolkit/tstring.cpp +++ b/taglib/toolkit/tstring.cpp @@ -48,11 +48,6 @@ namespace { - inline unsigned short combine(unsigned char c1, unsigned char c2) - { - return (c1 << 8) | c2; - } - void UTF16toUTF8(const wchar_t *src, size_t srcLength, char *dst, size_t dstLength) { #ifdef HAVE_STD_CODECVT @@ -844,7 +839,12 @@ void String::copyFromUTF16(const char *s, size_t length, Type t) d->data.resize(length / 2); for(size_t i = 0; i < length / 2; ++i) { - d->data[i] = swap ? combine(*s, *(s + 1)) : combine(*(s + 1), *s); + ushort c; + ::memcpy(&c, s, 2); + if(swap) + c = Utils::byteSwap(c); + + d->data[i] = static_cast(c); s += 2; } } -- 2.40.0