@@ -47,7 +47,7 @@ namespace cmcpp
4747 trap_if (cx, ptr + worst_case_size > cx.memory .size (), " Out of bounds access" );
4848
4949#ifdef SIMPLE_UTF16_CONVERSION
50- // Convert entire string to UTF-16 in one go, ignoring the previously copued data ---
50+ // Convert entire string to UTF-16 in one go, ignoring the previously computed data ---
5151 auto encoded = cx.convert (&cx.memory [ptr], worst_case_size, src, src_code_units * ValTrait<T>::char_size, src_encoding, Encoding::Utf16);
5252 if (encoded.second < worst_case_size)
5353 {
@@ -75,7 +75,7 @@ namespace cmcpp
7575 // Add special tag to indicate the string is a UTF-16 string ---
7676 uint32_t tagged_code_units = static_cast <uint32_t >(dst_byte_length + encoded.second / 2 ) | UTF16_TAG;
7777 return std::make_pair (ptr, tagged_code_units);
78- #endif // SIMPLE_UTF16_CONVERSION
78+ #endif
7979 }
8080 }
8181 if (dst_byte_length < src_code_units)
@@ -120,6 +120,8 @@ namespace cmcpp
120120 switch (cx.guest_encoding )
121121 {
122122 case Encoding::Latin1:
123+ cx.trap (" Invalid guest encoding, must be UTF8, UTF16 or Latin1/UTF16" );
124+ break ;
123125 case Encoding::Utf8:
124126 switch (src_simple_encoding)
125127 {
@@ -215,7 +217,7 @@ namespace cmcpp
215217 retVal.encoding = encoding;
216218 }
217219 retVal.resize (host_byte_length);
218- auto decoded = cx.convert (retVal.data (), host_byte_length, (void *)&cx.memory [ptr], byte_length, encoding, ValTrait<T>::encoding);
220+ auto decoded = cx.convert (retVal.data (), host_byte_length, (void *)&cx.memory [ptr], byte_length, encoding, ValTrait<T>::encoding == Encoding::Latin1_Utf16 ? encoding : ValTrait<T>::encoding );
219221 if ((decoded.second / char_size) < host_byte_length)
220222 {
221223 retVal.resize (decoded.second / char_size);
0 commit comments