--- CBOR-XS/XS.xs 2020/12/04 02:57:14 1.70 +++ CBOR-XS/XS.xs 2021/10/23 03:00:31 1.73 @@ -30,6 +30,9 @@ # define SvREFCNT_dec_NN(sv) SvREFCNT_dec (sv) #endif +// perl's is_utf8_string interprets len=0 as "calculate len", but we want it to mean 0 +#define cbor_is_utf8_string(str,len) (!(len) || is_utf8_string ((str), (len))) + // known major and minor types enum cbor_type { @@ -203,7 +206,7 @@ } // minimum length of a string to be registered for stringref -ecb_inline int +ecb_inline STRLEN minimum_string_length (UV idx) { return idx <= 23 ? 3 @@ -989,7 +992,7 @@ dec->cur += len; if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) - if (!is_utf8_string (key, len)) + if (!cbor_is_utf8_string ((U8 *)key, len)) ERR ("corrupted CBOR data (invalid UTF-8 in map key)"); hv_store (hv, key, -len, decode_sv (dec), 0); @@ -1128,7 +1131,7 @@ if (utf8) { if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) - if (!is_utf8_string (SvPVX (sv), SvCUR (sv))) + if (!cbor_is_utf8_string (SvPVX (sv), SvCUR (sv))) ERR ("corrupted CBOR data (invalid UTF-8 in text string)"); SvUTF8_on (sv); @@ -1571,6 +1574,7 @@ case MAJOR_MAP >> MAJOR_SHIFT: len <<= 1; + /* FALLTHROUGH */ case MAJOR_ARRAY >> MAJOR_SHIFT: if (len) {