Detect invalid values in StringUtils::Utf8CharSizeAt()

1164-fix
suve 2019-10-07 17:09:15 +02:00 committed by Mateusz Przybył
parent ebcb124b0e
commit 86ef158c00
1 changed files with 11 additions and 6 deletions

View File

@ -173,14 +173,19 @@ int StrUtils::Utf8CharSizeAt(const std::string &str, unsigned int pos)
if (pos >= str.size())
return 0;
if ((str[pos] & 0x80) == 0)
return 1;
else if ((str[pos] & 0xC0) == 0xC0)
return 2;
else
const char c = str[pos];
if(c >= 0xF0)
return 4;
if(c >= 0xE0)
return 3;
if(c >= 0xC0)
return 2;
return 0;
// Invalid char - unexpected continuation byte
if(c >= 0x80)
return 0;
return 1;
}
std::size_t StrUtils::Utf8StringLength(const std::string &str)