Skip to content

Commit

Permalink
Fixed bug with handling of malformed utf-8 at the end of a non-zero t…
Browse files Browse the repository at this point in the history
…erminated string range.
  • Loading branch information
ocornut committed Oct 9, 2015
1 parent b8281d9 commit fae7b34
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit fae7b34

Please sign in to comment.