Differences From Artifact [b713fffc4b]:
- File
src/OFString.m
— part of check-in
[5e2ef97c35]
at
2016-03-13 11:19:13
on branch trunk
— Change of_string_utf8_decode() API
It now returns <= 0 on error, with negative values being the number of
bytes it would have needed * -1.This can be used to detect cut off and how many bytes are missing. (user: js, size: 56129) [annotate] [blame] [check-ins using]
To Artifact [51291209ea]:
- File src/OFString.m — part of check-in [a83b261f72] at 2016-03-13 13:16:56 on branch trunk — of_string_utf8_decode(): Check all surrogate bytes (user: js, size: 56346) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
127 128 129 130 131 132 133 | return 0; } ssize_t of_string_utf8_decode(const char *buffer_, size_t length, of_unichar_t *ret) { | < > > > > > > > > > > > | 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | return 0; } ssize_t of_string_utf8_decode(const char *buffer_, size_t length, of_unichar_t *ret) { const uint8_t *buffer = (const uint8_t*)buffer_; if (!(*buffer & 0x80)) { *ret = buffer[0]; return 1; } if ((*buffer & 0xE0) == 0xC0) { if OF_UNLIKELY (length < 2) return -2; if OF_UNLIKELY ((buffer[1] & 0xC0) != 0x80) return 0; *ret = ((buffer[0] & 0x1F) << 6) | (buffer[1] & 0x3F); return 2; } if ((*buffer & 0xF0) == 0xE0) { if OF_UNLIKELY (length < 3) return -3; if OF_UNLIKELY ((buffer[1] & 0xC0) != 0x80 || (buffer[2] & 0xC0) != 0x80) return 0; *ret = ((buffer[0] & 0x0F) << 12) | ((buffer[1] & 0x3F) << 6) | (buffer[2] & 0x3F); return 3; } if ((*buffer & 0xF8) == 0xF0) { if OF_UNLIKELY (length < 4) return -4; if OF_UNLIKELY ((buffer[1] & 0xC0) != 0x80 || (buffer[2] & 0xC0) != 0x80 || (buffer[3] & 0xC0) != 0x80) return 0; *ret = ((buffer[0] & 0x07) << 18) | ((buffer[1] & 0x3F) << 12) | ((buffer[2] & 0x3F) << 6) | (buffer[3] & 0x3F); return 4; } return 0; |
︙ | ︙ |