mirror of
https://github.com/Drezil/imgui.git
synced 2024-12-18 06:06:35 +00:00
Fixed bug with handling of malformed utf-8 at the end of a non-zero terminated string range.
This commit is contained in:
parent
b8281d96bd
commit
fae7b34a3f
@ -908,7 +908,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char*
|
||||
if ((*str & 0xe0) == 0xc0)
|
||||
{
|
||||
*out_char = 0xFFFD; // will be invalid but not end of string
|
||||
if (in_text_end && in_text_end - (const char*)str < 2) return 0;
|
||||
if (in_text_end && in_text_end - (const char*)str < 2) return 1;
|
||||
if (*str < 0xc2) return 2;
|
||||
c = (unsigned int)((*str++ & 0x1f) << 6);
|
||||
if ((*str & 0xc0) != 0x80) return 2;
|
||||
@ -919,7 +919,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char*
|
||||
if ((*str & 0xf0) == 0xe0)
|
||||
{
|
||||
*out_char = 0xFFFD; // will be invalid but not end of string
|
||||
if (in_text_end && in_text_end - (const char*)str < 3) return 0;
|
||||
if (in_text_end && in_text_end - (const char*)str < 3) return 1;
|
||||
if (*str == 0xe0 && (str[1] < 0xa0 || str[1] > 0xbf)) return 3;
|
||||
if (*str == 0xed && str[1] > 0x9f) return 3; // str[1] < 0x80 is checked below
|
||||
c = (unsigned int)((*str++ & 0x0f) << 12);
|
||||
@ -933,7 +933,7 @@ int ImTextCharFromUtf8(unsigned int* out_char, const char* in_text, const char*
|
||||
if ((*str & 0xf8) == 0xf0)
|
||||
{
|
||||
*out_char = 0xFFFD; // will be invalid but not end of string
|
||||
if (in_text_end && in_text_end - (const char*)str < 4) return 0;
|
||||
if (in_text_end && in_text_end - (const char*)str < 4) return 1;
|
||||
if (*str > 0xf4) return 4;
|
||||
if (*str == 0xf0 && (str[1] < 0x90 || str[1] > 0xbf)) return 4;
|
||||
if (*str == 0xf4 && str[1] > 0x8f) return 4; // str[1] < 0x80 is checked below
|
||||
|
Loading…
Reference in New Issue
Block a user