Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed detection of overlong sequences (thanks Tommy!)
  • Loading branch information
slouken committed Jul 6, 2013
1 parent f27179a commit a3c9043
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/stdlib/SDL_iconv.c
Expand Up @@ -364,7 +364,7 @@ SDL_iconv(SDL_iconv_t cd,
*/ */
ch = UNKNOWN_UNICODE; ch = UNKNOWN_UNICODE;
} else { } else {
if (p[0] == 0xFC) { if (p[0] == 0xFC && srclen > 1 && (p[1] & 0xFC) == 0x80) {
overlong = SDL_TRUE; overlong = SDL_TRUE;
} }
ch = (Uint32) (p[0] & 0x01); ch = (Uint32) (p[0] & 0x01);
Expand All @@ -377,7 +377,7 @@ SDL_iconv(SDL_iconv_t cd,
*/ */
ch = UNKNOWN_UNICODE; ch = UNKNOWN_UNICODE;
} else { } else {
if (p[0] == 0xF8) { if (p[0] == 0xF8 && srclen > 1 && (p[1] & 0xF8) == 0x80) {
overlong = SDL_TRUE; overlong = SDL_TRUE;
} }
ch = (Uint32) (p[0] & 0x03); ch = (Uint32) (p[0] & 0x03);
Expand All @@ -390,7 +390,7 @@ SDL_iconv(SDL_iconv_t cd,
*/ */
ch = UNKNOWN_UNICODE; ch = UNKNOWN_UNICODE;
} else { } else {
if (p[0] == 0xF0) { if (p[0] == 0xF0 && srclen > 1 && (p[1] & 0xF0) == 0x80) {
overlong = SDL_TRUE; overlong = SDL_TRUE;
} }
ch = (Uint32) (p[0] & 0x07); ch = (Uint32) (p[0] & 0x07);
Expand All @@ -403,7 +403,7 @@ SDL_iconv(SDL_iconv_t cd,
*/ */
ch = UNKNOWN_UNICODE; ch = UNKNOWN_UNICODE;
} else { } else {
if (p[0] == 0xE0) { if (p[0] == 0xE0 && srclen > 1 && (p[1] & 0xE0) == 0x80) {
overlong = SDL_TRUE; overlong = SDL_TRUE;
} }
ch = (Uint32) (p[0] & 0x0F); ch = (Uint32) (p[0] & 0x0F);
Expand Down

0 comments on commit a3c9043

Please sign in to comment.