Fix condition for trailing bytes count in UTF-8 decoder. Test added to check if a replacement characters is added to output.
This commit is contained in:
parent
230c6a4d57
commit
692fe84331
@ -69,7 +69,7 @@ In Utf<8>::decode(In begin, In end, std::uint32_t& output, std::uint32_t replace
|
||||
|
||||
// decode the character
|
||||
int trailingBytes = trailing[static_cast<std::uint8_t>(*begin)];
|
||||
if (begin + trailingBytes < end)
|
||||
if (trailingBytes < std::distance(begin, end))
|
||||
{
|
||||
output = 0;
|
||||
|
||||
|
@ -229,6 +229,8 @@ TEST_CASE("[System] sf::String")
|
||||
}
|
||||
|
||||
SUBCASE("fromUtf8()")
|
||||
{
|
||||
SUBCASE("Nominal")
|
||||
{
|
||||
constexpr std::array<std::uint8_t, 4> characters{'w', 'x', 'y', 'z'};
|
||||
const sf::String string = sf::String::fromUtf8(characters.begin(), characters.end());
|
||||
@ -244,6 +246,16 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("Insufficient input")
|
||||
{
|
||||
constexpr std::array<std::uint8_t, 1> characters{251};
|
||||
const sf::String string = sf::String::fromUtf8(characters.begin(), characters.end());
|
||||
constexpr char32_t defaultReplacementCharacter = 0;
|
||||
CHECK(string.getSize() == 1);
|
||||
CHECK(string[0] == defaultReplacementCharacter);
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("fromUtf16()")
|
||||
{
|
||||
constexpr std::array<std::uint16_t, 4> characters{0xF1, 'x', 'y', 'z'};
|
||||
|
Loading…
Reference in New Issue
Block a user