Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Work around libstdc++ bug in codecvt_utf8_utf16::out
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Jun 6, 2017
1 parent a76eb2a commit 074c018
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/core/encoding-conversion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ int EncodingConversion::convert(

case UTF16_TO_UTF8: {
auto converter = static_cast<UTF8Converter *>(data);
const char *input_start = *input;
const char16_t *next_input;
char *next_output;
int result = converter->facet.out(
Expand All @@ -129,6 +130,13 @@ int EncodingConversion::convert(
*output = next_output;
switch (result) {
case codecvt_base::ok:
// When using GCC and libstdc++, `codecvt_utf8_utf16::out` seems to
// incorrectly return `ok` when there is an incomplete multi-byte
// sequence at the end of the input chunk. But it correctly does
// not advance the input pointer, so we can distinguish this
// situation from an actual successful result.
if (*input == input_start && input_start < input_end) return InvalidTrailing;

return Ok;
case codecvt_base::partial:
return (*input == input_end) ? Partial : InvalidTrailing;
Expand Down

0 comments on commit 074c018

Please sign in to comment.