Check for valid UTF-8 */
| 171 | |
| 172 | /* Check for valid UTF-8 */ |
| 173 | bool utf8_check(const void *vbuf, size_t buflen) |
| 174 | { |
| 175 | const u8 *buf = vbuf; |
| 176 | struct utf8_state utf8_state = UTF8_STATE_INIT; |
| 177 | bool need_more = false; |
| 178 | |
| 179 | for (size_t i = 0; i < buflen; i++) { |
| 180 | if (!utf8_decode(&utf8_state, buf[i])) { |
| 181 | need_more = true; |
| 182 | continue; |
| 183 | } |
| 184 | need_more = false; |
| 185 | if (errno != 0) |
| 186 | return false; |
| 187 | } |
| 188 | return !need_more; |
| 189 | } |
| 190 | |
| 191 | char *utf8_str(const tal_t *ctx, const u8 *buf TAKES, size_t buflen) |
| 192 | { |
no test coverage detected