diff options
Diffstat (limited to 'lutf8lib.c')
| -rw-r--r-- | lutf8lib.c | 4 |
1 files changed, 3 insertions, 1 deletions
| @@ -65,6 +65,8 @@ static const char *utf8_decode (const char *s, utfint *val, int strict) { | |||
| 65 | utfint res = 0; /* final result */ | 65 | utfint res = 0; /* final result */ |
| 66 | if (c < 0x80) /* ascii? */ | 66 | if (c < 0x80) /* ascii? */ |
| 67 | res = c; | 67 | res = c; |
| 68 | else if (c >= 0xfe) /* c >= 1111 1110b ? */ | ||
| 69 | return NULL; /* would need six or more continuation bytes */ | ||
| 68 | else { | 70 | else { |
| 69 | int count = 0; /* to count number of continuation bytes */ | 71 | int count = 0; /* to count number of continuation bytes */ |
| 70 | for (; c & 0x40; c <<= 1) { /* while it needs continuation bytes... */ | 72 | for (; c & 0x40; c <<= 1) { /* while it needs continuation bytes... */ |
| @@ -74,7 +76,7 @@ static const char *utf8_decode (const char *s, utfint *val, int strict) { | |||
| 74 | res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ | 76 | res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */ |
| 75 | } | 77 | } |
| 76 | res |= ((utfint)(c & 0x7F) << (count * 5)); /* add first byte */ | 78 | res |= ((utfint)(c & 0x7F) << (count * 5)); /* add first byte */ |
| 77 | if (count > 5 || res > MAXUTF || res < limits[count]) | 79 | if (res > MAXUTF || res < limits[count]) |
| 78 | return NULL; /* invalid byte sequence */ | 80 | return NULL; /* invalid byte sequence */ |
| 79 | s += count; /* skip continuation bytes read */ | 81 | s += count; /* skip continuation bytes read */ |
| 80 | } | 82 | } |
