Enforce buffer length in utf8_encode definition (#589)

Fixes: https://github.com/quickjs-ng/quickjs/issues/464
This commit is contained in:
Ben Noordhuis 2024-10-10 18:55:42 +02:00 committed by GitHub
parent 416dde8458
commit 681568353c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -246,7 +246,7 @@ size_t utf8_encode_len(uint32_t c)
No null byte is stored after the encoded bytes.
Return value is in range 1..4
*/
size_t utf8_encode(uint8_t *buf, uint32_t c)
size_t utf8_encode(uint8_t buf[minimum_length(UTF8_CHAR_LEN_MAX)], uint32_t c)
{
if (c < 0x80) {
buf[0] = c;

View file

@ -481,7 +481,7 @@ enum {
};
int utf8_scan(const char *buf, size_t len, size_t *plen);
size_t utf8_encode_len(uint32_t c);
size_t utf8_encode(uint8_t *buf, uint32_t c);
size_t utf8_encode(uint8_t buf[minimum_length(UTF8_CHAR_LEN_MAX)], uint32_t c);
uint32_t utf8_decode_len(const uint8_t *p, size_t max_len, const uint8_t **pp);
uint32_t utf8_decode(const uint8_t *p, const uint8_t **pp);
size_t utf8_decode_buf8(uint8_t *dest, size_t dest_len, const char *src, size_t src_len);