--- CBOR-XS/XS.xs 2021/03/19 17:30:27 1.71 +++ CBOR-XS/XS.xs 2023/09/07 23:57:58 1.76 @@ -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 { @@ -989,7 +992,7 @@ dec->cur += len; if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) - if (!is_utf8_string ((U8 *)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); @@ -1222,7 +1225,7 @@ if (!dec->shareable || idx >= (UV)(1 + AvFILLp (dec->shareable))) ERR ("corrupted CBOR data (sharedref index out of bounds)"); - sv = SvREFCNT_inc_NN (AvARRAY (dec->shareable)[idx]); + sv = newSVsv (AvARRAY (dec->shareable)[idx]); if (sv == &PL_sv_undef) ERR ("cyclic CBOR data structure found, but allow_cycles is not enabled"); @@ -1472,7 +1475,7 @@ if (dec.err_sv) sv_2mortal (dec.err_sv); - croak ("%s, at offset %d (octet 0x%02x)", dec.err, dec.cur - (U8 *)data, (int)(uint8_t)*dec.cur); + croak ("%s, at offset %ld (octet 0x%02x)", dec.err, (long)(dec.cur - (U8 *)data), (int)(uint8_t)*dec.cur); } sv = sv_2mortal (sv);