Check for valid UTF-8 */
| 186 | |
| 187 | /* Check for valid UTF-8 */ |
| 188 | bool utf8_check(const void *vbuf, size_t buflen) |
| 189 | { |
| 190 | const u8 *buf = vbuf; |
| 191 | struct utf8_state utf8_state = UTF8_STATE_INIT; |
| 192 | bool need_more = false; |
| 193 | |
| 194 | for (size_t i = 0; i < buflen; i++) { |
| 195 | if (!utf8_decode(&utf8_state, buf[i])) { |
| 196 | need_more = true; |
| 197 | continue; |
| 198 | } |
| 199 | need_more = false; |
| 200 | if (errno != 0) |
| 201 | return false; |
| 202 | } |
| 203 | return !need_more; |
| 204 | } |
| 205 | |
| 206 | char *utf8_str(const tal_t *ctx, const u8 *buf TAKES, size_t buflen) |
| 207 | { |
no test coverage detected