… | |
… | |
332 | SV **svp = av_fetch (av, i, 0); |
332 | SV **svp = av_fetch (av, i, 0); |
333 | encode_sv (enc, svp ? *svp : &PL_sv_undef); |
333 | encode_sv (enc, svp ? *svp : &PL_sv_undef); |
334 | } |
334 | } |
335 | else |
335 | else |
336 | for (i = 0; i <= len; ++i) |
336 | for (i = 0; i <= len; ++i) |
337 | encode_sv (enc, AvARRAY (av)[i]); |
337 | { |
|
|
338 | SV *sv = AvARRAY (av)[i]; |
|
|
339 | encode_sv (enc, sv ? sv : &PL_sv_undef); |
|
|
340 | } |
338 | |
341 | |
339 | --enc->depth; |
342 | --enc->depth; |
340 | } |
343 | } |
341 | |
344 | |
342 | static void |
345 | static void |
… | |
… | |
581 | } |
584 | } |
582 | |
585 | |
583 | static SV * |
586 | static SV * |
584 | encode_cbor (SV *scalar, CBOR *cbor) |
587 | encode_cbor (SV *scalar, CBOR *cbor) |
585 | { |
588 | { |
586 | enc_t enc = { }; |
589 | enc_t enc = { 0 }; |
587 | |
590 | |
588 | enc.cbor = *cbor; |
591 | enc.cbor = *cbor; |
589 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
592 | enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); |
590 | enc.cur = SvPVX (enc.sv); |
593 | enc.cur = SvPVX (enc.sv); |
591 | enc.end = SvEND (enc.sv); |
594 | enc.end = SvEND (enc.sv); |
… | |
… | |
746 | if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8)) |
749 | if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8)) |
747 | { |
750 | { |
748 | I32 len = decode_uint (dec); |
751 | I32 len = decode_uint (dec); |
749 | char *key = (char *)dec->cur; |
752 | char *key = (char *)dec->cur; |
750 | |
753 | |
|
|
754 | WANT (len); |
751 | dec->cur += len; |
755 | dec->cur += len; |
752 | |
756 | |
753 | hv_store (hv, key, len, decode_sv (dec), 0); |
757 | hv_store (hv, key, len, decode_sv (dec), 0); |
754 | |
758 | |
755 | return; |
759 | return; |
756 | } |
760 | } |
757 | else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) |
761 | else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) |
758 | { |
762 | { |
759 | I32 len = decode_uint (dec); |
763 | I32 len = decode_uint (dec); |
760 | char *key = (char *)dec->cur; |
764 | char *key = (char *)dec->cur; |
761 | |
765 | |
|
|
766 | WANT (len); |
762 | dec->cur += len; |
767 | dec->cur += len; |
763 | |
768 | |
764 | if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) |
769 | if (ecb_expect_false (dec->cbor.flags & F_VALIDATE_UTF8)) |
765 | if (!is_utf8_string (key, len)) |
770 | if (!is_utf8_string (key, len)) |
766 | ERR ("corrupted CBOR data (invalid UTF-8 in map key)"); |
771 | ERR ("corrupted CBOR data (invalid UTF-8 in map key)"); |
… | |
… | |
1160 | } |
1165 | } |
1161 | |
1166 | |
1162 | static SV * |
1167 | static SV * |
1163 | decode_cbor (SV *string, CBOR *cbor, char **offset_return) |
1168 | decode_cbor (SV *string, CBOR *cbor, char **offset_return) |
1164 | { |
1169 | { |
1165 | dec_t dec = { }; |
1170 | dec_t dec = { 0 }; |
1166 | SV *sv; |
1171 | SV *sv; |
1167 | STRLEN len; |
1172 | STRLEN len; |
1168 | char *data = SvPVbyte (string, len); |
1173 | char *data = SvPVbyte (string, len); |
1169 | |
1174 | |
1170 | if (len > cbor->max_size && cbor->max_size) |
1175 | if (len > cbor->max_size && cbor->max_size) |
… | |
… | |
1261 | |
1266 | |
1262 | int major = *p >> MAJOR_SHIFT; |
1267 | int major = *p >> MAJOR_SHIFT; |
1263 | |
1268 | |
1264 | switch (major) |
1269 | switch (major) |
1265 | { |
1270 | { |
|
|
1271 | case MAJOR_TAG >> MAJOR_SHIFT: |
|
|
1272 | ++count; // tags merely prefix another value |
|
|
1273 | break; |
|
|
1274 | |
1266 | case MAJOR_BYTES >> MAJOR_SHIFT: |
1275 | case MAJOR_BYTES >> MAJOR_SHIFT: |
1267 | case MAJOR_TEXT >> MAJOR_SHIFT: |
1276 | case MAJOR_TEXT >> MAJOR_SHIFT: |
1268 | case MAJOR_ARRAY >> MAJOR_SHIFT: |
1277 | case MAJOR_ARRAY >> MAJOR_SHIFT: |
1269 | case MAJOR_MAP >> MAJOR_SHIFT: |
1278 | case MAJOR_MAP >> MAJOR_SHIFT: |
1270 | { |
1279 | { |