Util: Make the length parameter for utf8Char nullable

This commit is contained in:
Vicki Pfau 2025-05-31 22:52:13 -07:00
parent 92ca66be7c
commit 8a4750f4fe
1 changed files with 8 additions and 4 deletions

View File

@ -124,11 +124,13 @@ static const uint8_t _utf8len[0x40] = {
}; };
uint32_t utf8Char(const char** unicode, size_t* length) { uint32_t utf8Char(const char** unicode, size_t* length) {
if (*length == 0) { if (length && *length == 0) {
return 0; return 0;
} }
unsigned char byte = **unicode; unsigned char byte = **unicode;
--*length; if (length) {
--*length;
}
++*unicode; ++*unicode;
if (!(byte & 0x80)) { if (!(byte & 0x80)) {
return byte; return byte;
@ -140,7 +142,7 @@ uint32_t utf8Char(const char** unicode, size_t* length) {
if (numBytes == 0) { if (numBytes == 0) {
return 0xFFFD; return 0xFFFD;
} }
if (*length + 1 < numBytes) { if (length && *length + 1 < numBytes) {
*length = 0; *length = 0;
return 0xFFFD; return 0xFFFD;
} }
@ -148,7 +150,9 @@ uint32_t utf8Char(const char** unicode, size_t* length) {
for (i = 1; i < numBytes; ++i) { for (i = 1; i < numBytes; ++i) {
unichar <<= 6; unichar <<= 6;
byte = **unicode; byte = **unicode;
--*length; if (length) {
--*length;
}
++*unicode; ++*unicode;
if ((byte & 0xC0) != 0x80) { if ((byte & 0xC0) != 0x80) {
return 0; return 0;