11f5584
From 40929842565a5c4cac4886317ef4ab9de64a3ba7 Mon Sep 17 00:00:00 2001
11f5584
From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= <guenter.obiltschnig@appinf.com>
11f5584
Date: Sat, 8 Feb 2020 20:25:00 +0100
11f5584
Subject: [PATCH] fix UTF16/UTF32Encoding wrong byte order handling on
11f5584
 bigendian
11f5584
11f5584
---
11f5584
 Foundation/src/UTF16Encoding.cpp | 58 +++++++++++++++++---------------
11f5584
 Foundation/src/UTF32Encoding.cpp | 50 ++++++++++++++-------------
11f5584
 2 files changed, 57 insertions(+), 51 deletions(-)
11f5584
11f5584
diff --git a/Foundation/src/UTF16Encoding.cpp b/Foundation/src/UTF16Encoding.cpp
11f5584
index ea2ee8fe4f..ae7ac88733 100644
11f5584
--- a/Foundation/src/UTF16Encoding.cpp
11f5584
+++ b/Foundation/src/UTF16Encoding.cpp
11f5584
@@ -28,24 +28,24 @@ const char* UTF16Encoding::_names[] =
11f5584
 };
11f5584
 
11f5584
 
11f5584
-const TextEncoding::CharacterMap UTF16Encoding::_charMap = 
11f5584
+const TextEncoding::CharacterMap UTF16Encoding::_charMap =
11f5584
 {
11f5584
-	/* 00 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 10 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 20 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 30 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 40 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 50 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 60 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 70 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 80 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 90 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* a0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* b0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* c0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* d0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* e0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* f0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
+	/* 00 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 10 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 20 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 30 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 40 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 50 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 60 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 70 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 80 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 90 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* a0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* b0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* c0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* d0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* e0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* f0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
 };
11f5584
 
11f5584
 
11f5584
@@ -54,13 +54,13 @@ UTF16Encoding::UTF16Encoding(ByteOrderType byteOrder)
11f5584
 	setByteOrder(byteOrder);
11f5584
 }
11f5584
 
11f5584
-	
11f5584
+
11f5584
 UTF16Encoding::UTF16Encoding(int byteOrderMark)
11f5584
 {
11f5584
 	setByteOrder(byteOrderMark);
11f5584
 }
11f5584
 
11f5584
-	
11f5584
+
11f5584
 UTF16Encoding::~UTF16Encoding()
11f5584
 {
11f5584
 }
11f5584
@@ -75,7 +75,7 @@ UTF16Encoding::ByteOrderType UTF16Encoding::getByteOrder() const
11f5584
 #endif
11f5584
 }
11f5584
 
11f5584
-	
11f5584
+
11f5584
 void UTF16Encoding::setByteOrder(ByteOrderType byteOrder)
11f5584
 {
11f5584
 #if defined(POCO_ARCH_BIG_ENDIAN)
11f5584
@@ -85,7 +85,7 @@ void UTF16Encoding::setByteOrder(ByteOrderType byteOrder)
11f5584
 #endif
11f5584
 }
11f5584
 
11f5584
-	
11f5584
+
11f5584
 void UTF16Encoding::setByteOrder(int byteOrderMark)
11f5584
 {
11f5584
 	_flipBytes = byteOrderMark != 0xFEFF;
11f5584
@@ -124,7 +124,7 @@ int UTF16Encoding::convert(const unsigned char* bytes) const
11f5584
 
11f5584
 	if (_flipBytes)
11f5584
 	{
11f5584
-		ByteOrder::flipBytes(uc);
11f5584
+		uc = ByteOrder::flipBytes(uc);
11f5584
 	}
11f5584
 
11f5584
 	if (uc >= 0xd800 && uc < 0xdc00)
11f5584
@@ -136,7 +136,7 @@ int UTF16Encoding::convert(const unsigned char* bytes) const
11f5584
 
11f5584
 		if (_flipBytes)
11f5584
 		{
11f5584
-			ByteOrder::flipBytes(uc2);
11f5584
+			uc2 = ByteOrder::flipBytes(uc2);
11f5584
 		}
11f5584
 		if (uc2 >= 0xdc00 && uc2 < 0xe000)
11f5584
 		{
11f5584
@@ -201,8 +201,10 @@ int UTF16Encoding::queryConvert(const unsigned char* bytes, int length) const
11f5584
 		unsigned char* p = (unsigned char*) &uc;
11f5584
 		*p++ = *bytes++;
11f5584
 		*p++ = *bytes++;
11f5584
-		if (_flipBytes) 
11f5584
-			ByteOrder::flipBytes(uc);
11f5584
+		if (_flipBytes)
11f5584
+		{
11f5584
+			uc = ByteOrder::flipBytes(uc);
11f5584
+		}
11f5584
 		if (uc >= 0xd800 && uc < 0xdc00)
11f5584
 		{
11f5584
 			if (length >= 4)
11f5584
@@ -211,8 +213,10 @@ int UTF16Encoding::queryConvert(const unsigned char* bytes, int length) const
11f5584
 				p = (unsigned char*) &uc2;
11f5584
 				*p++ = *bytes++;
11f5584
 				*p++ = *bytes++;
11f5584
-				if (_flipBytes) 
11f5584
-					ByteOrder::flipBytes(uc2);
11f5584
+				if (_flipBytes)
11f5584
+				{
11f5584
+					uc2 = ByteOrder::flipBytes(uc2);
11f5584
+				}
11f5584
 				if (uc2 >= 0xdc00 && uc < 0xe000)
11f5584
 				{
11f5584
 					ret = ((uc & 0x3ff) << 10) + (uc2 & 0x3ff) + 0x10000;
11f5584
diff --git a/Foundation/src/UTF32Encoding.cpp b/Foundation/src/UTF32Encoding.cpp
11f5584
index ff07006a4f..47a0156b0e 100644
11f5584
--- a/Foundation/src/UTF32Encoding.cpp
11f5584
+++ b/Foundation/src/UTF32Encoding.cpp
11f5584
@@ -28,24 +28,24 @@ const char* UTF32Encoding::_names[] =
11f5584
 };
11f5584
 
11f5584
 
11f5584
-const TextEncoding::CharacterMap UTF32Encoding::_charMap = 
11f5584
+const TextEncoding::CharacterMap UTF32Encoding::_charMap =
11f5584
 {
11f5584
-	/* 00 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 10 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 20 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 30 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 40 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 50 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 60 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 70 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 80 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* 90 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* a0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* b0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* c0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* d0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* e0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
-	/* f0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 
11f5584
+	/* 00 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 10 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 20 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 30 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 40 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 50 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 60 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 70 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 80 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* 90 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* a0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* b0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* c0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* d0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* e0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
+	/* f0 */	-2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2,
11f5584
 };
11f5584
 
11f5584
 
11f5584
@@ -54,13 +54,13 @@ UTF32Encoding::UTF32Encoding(ByteOrderType byteOrder)
11f5584
 	setByteOrder(byteOrder);
11f5584
 }
11f5584
 
11f5584
-	
11f5584
+
11f5584
 UTF32Encoding::UTF32Encoding(int byteOrderMark)
11f5584
 {
11f5584
 	setByteOrder(byteOrderMark);
11f5584
 }
11f5584
 
11f5584
-	
11f5584
+
11f5584
 UTF32Encoding::~UTF32Encoding()
11f5584
 {
11f5584
 }
11f5584
@@ -75,7 +75,7 @@ UTF32Encoding::ByteOrderType UTF32Encoding::getByteOrder() const
11f5584
 #endif
11f5584
 }
11f5584
 
11f5584
-	
11f5584
+
11f5584
 void UTF32Encoding::setByteOrder(ByteOrderType byteOrder)
11f5584
 {
11f5584
 #if defined(POCO_ARCH_BIG_ENDIAN)
11f5584
@@ -85,7 +85,7 @@ void UTF32Encoding::setByteOrder(ByteOrderType byteOrder)
11f5584
 #endif
11f5584
 }
11f5584
 
11f5584
-	
11f5584
+
11f5584
 void UTF32Encoding::setByteOrder(int byteOrderMark)
11f5584
 {
11f5584
 	_flipBytes = byteOrderMark != 0xFEFF;
11f5584
@@ -126,7 +126,7 @@ int UTF32Encoding::convert(const unsigned char* bytes) const
11f5584
 
11f5584
 	if (_flipBytes)
11f5584
 	{
11f5584
-		ByteOrder::flipBytes(uc);
11f5584
+		uc = ByteOrder::flipBytes(uc);
11f5584
 	}
11f5584
 
11f5584
 	return uc;
11f5584
@@ -160,8 +160,10 @@ int UTF32Encoding::queryConvert(const unsigned char* bytes, int length) const
11f5584
 		*p++ = *bytes++;
11f5584
 		*p++ = *bytes++;
11f5584
 		*p++ = *bytes++;
11f5584
-		if (_flipBytes) 
11f5584
-			ByteOrder::flipBytes(uc);
11f5584
+		if (_flipBytes)
11f5584
+		{
11f5584
+			uc = ByteOrder::flipBytes(uc);
11f5584
+		}
11f5584
 		return uc;
11f5584
 	}
11f5584