Changes in common/stdc/uchar.c [0600976:696b405] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • common/stdc/uchar.c

    r0600976 r696b405  
    8484}
    8585
    86 static bool _is_non_shortest(unsigned short cont, uint8_t b)
    87 {
    88         return (cont == 0b1111110000000000 && !(b & 0b00100000)) ||
    89             (cont == 0b1111111111110000 && !(b & 0b00110000));
    90 }
    91 
    9286size_t mbrtoc32(char32_t *c, const char *s, size_t n, mbstate_t *mb)
    9387{
     
    145139
    146140                if (_is_2_byte(b)) {
    147                         /* Reject non-shortest form. */
    148                         if (!(b & 0b00011110)) {
    149                                 _set_ilseq();
    150                                 return UCHAR_ILSEQ;
    151                         }
    152 
    153141                        /* 2 byte encoding               110xxxxx */
    154142                        mb->continuation = b ^ 0b0000000011000000;
     
    164152        }
    165153
    166         for (; i < n; i++) {
     154        while (i < n) {
    167155                /* Read continuation bytes. */
    168                 uint8_t b = s[i];
    169 
    170                 if (!_is_continuation(b) || _is_non_shortest(mb->continuation, b)) {
     156
     157                if (!_is_continuation(s[i])) {
    171158                        _set_ilseq();
    172159                        return UCHAR_ILSEQ;
     
    175162                /* Top bit becomes zero just before the last byte is shifted in. */
    176163                if (!(mb->continuation & 0x8000)) {
    177                         *c = ((char32_t) mb->continuation) << 6 | (b & 0x3f);
     164                        *c = ((char32_t) mb->continuation) << 6 | (s[i++] & 0x3f);
    178165                        mb->continuation = 0;
    179                         return ++i;
    180                 }
    181 
    182                 mb->continuation = mb->continuation << 6 | (b & 0x3f);
     166                        return i;
     167                }
     168
     169                mb->continuation = mb->continuation << 6 | (s[i++] & 0x3f);
    183170        }
    184171
Note: See TracChangeset for help on using the changeset viewer.