Branch Coverage

XS.xs
Criterion Covered Total %
branch 345 610 56.5


line true false branch
56 0 10 if (json_true_cache && json_false_cache)
0 0 if (json_true_cache && json_false_cache)
58 0 10 if (!eval_pv("require JSON::PP; 1", TRUE))
65 0 10 PUSHMARK(SP);
72 0 10 PUSHMARK(SP);
79 10 0 FREETMPS;
84 0 190132 if (r->p >= r->end)
89 0 4051 if ((size_t)(r->end - r->p) < n)
99 8594 13333 if (b & 0x80) {
113 5 92 if (SvLEN(out) <= cur + 1)
114 5 0 (void)SvGROW(out, cur + 2);
5 0 (void)SvGROW(out, cur + 2);
122 0 43 if (n == 0)
125 3 40 if (SvLEN(out) <= cur + (STRLEN)n)
126 3 0 (void)SvGROW(out, cur + (STRLEN)n + 1);
3 0 (void)SvGROW(out, cur + (STRLEN)n + 1);
140 0 0 while (u) {
152 0 0 for (size_t g = 0; g < groups; g++) {
154 0 0 int take = (remain >= 7) ? 7 : (int)remain;
156 0 0 for (int j = 0; j < take; j++) {
161 0 0 out7 |= (unsigned char)(bit << (take == 7 ? (6 - j) : (take - 1 - j)));
170 2 0 SvGROW(sv, (STRLEN)raw_len + 1);
0 2 SvGROW(sv, (STRLEN)raw_len + 1);
178 30 2 for (size_t g = 0; g < groups; g++) {
180 2 28 int take = (remain >= 7) ? 7 : (int)remain;
182 208 30 for (int j = 0; j < take; j++) {
184 196 12 (unsigned char)((in7 >> (take == 7 ? (6 - j) : (take - 1 - j))) & 1u);
203 69 40 for (size_t i = 0; i < n; i++)
204 0 69 if (p[i] & 0x80)
216 0 0 for (int i = 0; i < (nbits / 8); i++)
222 0 0 if (take > 0) {
223 0 0 uint64_t mask = (take == 64) ? ~0ULL : ((1ULL << take) - 1ULL);
229 0 0 while (pos > 0) {
246 5133 5133 for (int j = 0; j < take0; j++) {
254 46197 5133 for (int i = 1; i < groups; i++) {
256 323379 46197 for (int j = 0; j < 7; j++) {
257 0 323379 if (bitpos >= nbits)
267 0 5133 if (nbits == 32) {
269 0 0 for (int i = 0; i < 4; i++)
277 41064 5133 for (int i = 0; i < 8; i++)
286 0 21 if (!SvROK(sv))
289 20 1 if (!SvOBJECT(rv))
292 1 0 if (gv_fetchmethod_autoload(SvSTASH(rv), "TO_JSON", 0)) {
296 0 1 PUSHMARK(SP);
297 0 1 XPUSHs(sv);
301 0 1 if (count != 1) {
303 0 0 FREETMPS;
310 1 0 FREETMPS;
320 21 1 if (!he)
323 0 1 if (!SvOK(v))
335 6 8 if (!svp || !SvOK(*svp))
0 6 if (!svp || !SvOK(*svp))
354 1 9 if (len == 0) {
359 9 0 if (ascii) {
360 9 0 if (len <= 32) {
363 0 0 } else if (len <= 64) {
372 0 0 if (len >= 2 && len <= 33) {
0 0 if (len >= 2 && len <= 33) {
375 0 0 } else if (len >= 34 && len <= 65) {
0 0 } else if (len >= 34 && len <= 65) {
385 9 0 if (*out_is_short) {
388 0 9 if (!ascii)
398 0 2 if (SvUTF8(tmp))
412 0 24 if (SvUTF8(tmp))
419 0 24 if (len == 0) {
426 24 0 if (ascii && len <= 64) {
24 0 if (ascii && len <= 64) {
431 0 0 if (!ascii && len >= 2 && len <= 57) {
0 0 if (!ascii && len >= 2 && len <= 57) {
0 0 if (!ascii && len >= 2 && len <= 57) {
444 0 24 if (!ascii)
453 14 2 if (ctx->shared_values) {
460 0 14 if (SvUTF8(tmp))
466 14 0 if (is_short && ascii) {
14 0 if (is_short && ascii) {
468 6 8 if (enc_lookup_shared_ascii(aTHX_ shared_map, s, len, &index) &&
469 6 0 index >= 0) {
470 6 0 if (index < 31) {
474 0 0 if (index < 1024) {
480 0 0 } else if (is_short) {
482 0 0 if (!ascii)
486 0 0 if (enc_lookup_shared(aTHX_ shared_map, vkey, &index) && index >= 0) {
0 0 if (enc_lookup_shared(aTHX_ shared_map, vkey, &index) && index >= 0) {
487 0 0 if (index < 31) {
492 0 0 if (index < 1024) {
504 8 0 if (was_short) {
506 8 0 if (idx < MAX_SHARED_VALUES) {
507 8 0 if (valid_backref_index(idx)) {
508 8 0 if (ascii)
517 0 0 if (valid_backref_index(0)) {
518 0 0 if (ascii)
527 0 8 if (vkey)
529 7 1 if (k2)
538 2 0 if (k)
545 0 15 if (SvUOK(sv) && !SvNOK(sv)) {
0 0 if (SvUOK(sv) && !SvNOK(sv)) {
547 0 0 if (uv <= (uint64_t)INT64_MAX) {
549 0 0 if (v >= -16 && v <= 15) {
0 0 if (v >= -16 && v <= 15) {
554 0 0 if (v >= INT32_MIN && v <= INT32_MAX) {
0 0 if (v >= INT32_MIN && v <= INT32_MAX) {
566 0 0 for (int i = 7; i >= 0; i--) {
570 0 0 if (be[0] & 0x80) {
582 15 0 if (SvIOK(sv) && !SvNOK(sv)) {
15 0 if (SvIOK(sv) && !SvNOK(sv)) {
585 15 0 if (v >= -16 && v <= 15) {
15 0 if (v >= -16 && v <= 15) {
590 0 0 if (v >= INT32_MIN && v <= INT32_MAX) {
0 0 if (v >= INT32_MIN && v <= INT32_MAX) {
606 0 0 for (int i = 7; i >= 0; i--) {
615 31 21 if (!SvROK(sv))
618 20 1 if (!SvOBJECT(rv))
621 1 0 const char *pkg = HvNAME(SvSTASH(rv));
1 0 const char *pkg = HvNAME(SvSTASH(rv));
0 1 const char *pkg = HvNAME(SvSTASH(rv));
0 0 const char *pkg = HvNAME(SvSTASH(rv));
1 0 const char *pkg = HvNAME(SvSTASH(rv));
0 1 const char *pkg = HvNAME(SvSTASH(rv));
622 0 1 if (!pkg)
625 1 0 if (strEQ(pkg, "JSON::PP::Boolean") || strEQ(pkg, "JSON::XS::Boolean") ||
1 0 if (strEQ(pkg, "JSON::PP::Boolean") || strEQ(pkg, "JSON::XS::Boolean") ||
626 0 1 strEQ(pkg, "Cpanel::JSON::XS::Boolean")) {
636 22 3 if (ctx->shared_names) {
638 1 21 if (enc_lookup_shared(aTHX_(HV *) SvRV(ctx->seen_names_map), k, &index) && index >= 0) {
1 0 if (enc_lookup_shared(aTHX_(HV *) SvRV(ctx->seen_names_map), k, &index) && index >= 0) {
639 1 0 if (index < 64) {
644 0 0 if (index < 1024) {
657 21 3 if (ctx->shared_names && trackable) {
21 0 if (ctx->shared_names && trackable) {
659 21 0 if (idx < MAX_SHARED_NAMES) {
660 21 0 if (valid_backref_index(idx)) {
668 0 0 if (valid_backref_index(0))
673 24 0 if (kkey)
682 13 1 if (!ctx->canonical) {
685 22 13 while ((he = hv_iternext(hv)) != NULL) {
691 0 1 SSize_t count = HvUSEDKEYS(hv);
692 1 0 if (count > 0) {
699 0 1 Newx(entries, (size_t)count, smile_hash_entry_t);
704 3 1 while ((he = hv_iternext(hv)) != NULL) {
710 2 1 for (SSize_t i = 1; i < used; i++) {
713 2 1 while (j > 0 && sv_cmp(current.k, entries[j - 1].k) < 0) {
1 1 while (j > 0 && sv_cmp(current.k, entries[j - 1].k) < 0) {
720 3 1 for (SSize_t i = 0; i < used; i++) {
735 14 6 for (SSize_t i = 0; i <= n; i++) {
737 14 0 SV *v = svp ? *svp : &PL_sv_undef;
744 53 0 if (!sv || !SvOK(sv)) {
1 52 if (!sv || !SvOK(sv)) {
750 0 52 if (is_json_boolean_sv(aTHX_ sv, &b)) {
751 0 0 wr_u8(aTHX_ out, b ? 0x23 : 0x22);
755 21 31 if (SvROK(sv)) {
757 1 20 if (maybe != sv) {
764 6 14 if (SvTYPE(rv) == SVt_PVAV) {
768 14 0 if (SvTYPE(rv) == SVt_PVHV) {
772 0 0 if (SvTYPE(rv) == SVt_PV) {
777 0 0 if (SvTYPE(rv) == SVt_IV || SvTYPE(rv) == SVt_NV || SvTYPE(rv) == SVt_PVIV ||
0 0 if (SvTYPE(rv) == SVt_IV || SvTYPE(rv) == SVt_NV || SvTYPE(rv) == SVt_PVIV ||
0 0 if (SvTYPE(rv) == SVt_IV || SvTYPE(rv) == SVt_NV || SvTYPE(rv) == SVt_PVIV ||
778 0 0 SvTYPE(rv) == SVt_PVNV) {
786 31 0 if (SvOK(sv) && SvPOK(sv) && !SvIOK(sv) && !SvNOK(sv)) {
16 15 if (SvOK(sv) && SvPOK(sv) && !SvIOK(sv) && !SvNOK(sv)) {
16 0 if (SvOK(sv) && SvPOK(sv) && !SvIOK(sv) && !SvNOK(sv)) {
16 0 if (SvOK(sv) && SvPOK(sv) && !SvIOK(sv) && !SvNOK(sv)) {
791 0 15 if (SvIOK(sv) || SvNOK(sv)) {
0 0 if (SvIOK(sv) || SvNOK(sv)) {
807 4051 0 SvGROW(sv, (STRLEN)len + 1);
873 3178 SvGROW(sv, (STRLEN)len + 1);
812 17 4034 if (set_utf8)
819 0 471 if (!stop)
825 18 453 if (!ascii_hint)
830 2577 2556 NV absn = n < 0 ? -n : n;
831 1477 3656 if (absn >= 9.0e15) {
832 832 645 if (n >= (NV)IV_MIN && n <= (NV)IV_MAX) {
185 647 if (n >= (NV)IV_MIN && n <= (NV)IV_MAX) {
834 185 0 if ((NV)iv == n)
838 647 645 if (n >= 0.0 && n <= (NV)UV_MAX) {
13 634 if (n >= 0.0 && n <= (NV)UV_MAX) {
840 13 0 if ((NV)uv == n)
849 5 0 if (use_json_bool && json_true_cache && json_false_cache)
5 0 if (use_json_bool && json_true_cache && json_false_cache)
5 0 if (use_json_bool && json_true_cache && json_false_cache)
850 3 2 return newSVsv( b ? json_true_cache : json_false_cache );
851 0 0 return b ? &PL_sv_yes : &PL_sv_no;
855 0 718 if (!ctx->shared_names)
858 0 718 if (idx >= MAX_SHARED_NAMES) {
859 0 0 for (int i = 0; i < ctx->seen_name_count; i++)
864 718 0 if (valid_backref_index(idx)) {
874 5 3328 if (!ctx->shared_values)
878 0 3328 if (len > 64)
882 1 3327 if (idx >= MAX_SHARED_VALUES) {
883 1024 1 for (int i = 0; i < ctx->seen_value_count; i++)
888 3328 0 if (valid_backref_index(idx)) {
901 0 20256 if (r->p >= r->end)
904 732 19524 if (peek == 0xF9) {
920 10588 33607 if (t == 0xFB)
925 0 33607 if (t == 0x20) {
927 23723 9884 } else if (t >= 0x40 && t <= 0x7F) {
23005 718 } else if (t >= 0x40 && t <= 0x7F) {
930 23005 0 if (!ctx->shared_names || index >= ctx->seen_name_count)
0 23005 if (!ctx->shared_names || index >= ctx->seen_name_count)
934 718 9884 } else if (t >= 0x80 && t <= 0xBF) {
717 1 } else if (t >= 0x80 && t <= 0xBF) {
938 1 9884 } else if (t >= 0xC0 && t <= 0xF7) {
1 0 } else if (t >= 0xC0 && t <= 0xF7) {
942 9884 0 } else if (t >= 0x30 && t <= 0x33) {
9884 0 } else if (t >= 0x30 && t <= 0x33) {
945 9884 0 if (!ctx->shared_names || index >= ctx->seen_name_count)
0 9884 if (!ctx->shared_names || index >= ctx->seen_name_count)
949 0 0 } else if (t == 0x34) {
967 0 53160 if (t == 0xFF)
970 4 53156 if (t == 0x20)
972 6 53150 if (t == 0x21)
974 2 53148 if (t == 0x22)
976 3 53145 if (t == 0x23)
979 732 52413 if (t == 0xF8)
981 10588 41825 if (t == 0xFA)
989 41825 0 if (t >= 0x01 && t <= 0x1F) {
11415 30410 if (t >= 0x01 && t <= 0x1F) {
991 11415 0 if (!ctx->shared_values || index >= ctx->seen_value_count)
0 11415 if (!ctx->shared_values || index >= ctx->seen_value_count)
995 9606 20804 if ((t & 0xFC) == 0xEC) {
998 9606 0 if (!ctx->shared_values || index >= ctx->seen_value_count)
0 9606 if (!ctx->shared_values || index >= ctx->seen_value_count)
1004 3047 17757 if ((t & 0xE0) == 0x40) {
1010 270 17487 if ((t & 0xE0) == 0x60) {
1016 14 17473 if ((t & 0xE0) == 0x80) {
1022 2 17471 if ((t & 0xE0) == 0xA0) {
1030 3273 14198 if ((t & 0xE0) == 0xC0) {
1036 5606 8592 if (t == 0x24 || t == 0x25) {
0 5606 if (t == 0x24 || t == 0x25) {
1039 8592 0 if (t == 0x24 && (v < INT32_MIN || v > INT32_MAX))
8592 0 if (t == 0x24 && (v < INT32_MIN || v > INT32_MAX))
0 8592 if (t == 0x24 && (v < INT32_MIN || v > INT32_MAX))
1044 2 5604 if (t == 0x26) {
1046 0 2 if (raw_len_u == 0)
1048 0 2 if (raw_len_u > 1024)
1056 2 0 if (n <= 8 || (n == 9 && !negative && bp[0] == 0x00)) {
0 2 if (n <= 8 || (n == 9 && !negative && bp[0] == 0x00)) {
0 0 if (n <= 8 || (n == 9 && !negative && bp[0] == 0x00)) {
0 0 if (n <= 8 || (n == 9 && !negative && bp[0] == 0x00)) {
1058 0 0 if (n == 9) {
1063 0 0 for (STRLEN i = 0; i < n; i++)
1066 0 0 if (!negative) {
1067 0 0 if (uv <= (uint64_t)IV_MAX)
1076 1 1 if (ctx->use_bigint && eval_pv("require Math::BigInt; 1", TRUE)) {
1 0 if (ctx->use_bigint && eval_pv("require Math::BigInt; 1", TRUE)) {
1077 0 1 SV *hex = newSVpvn(negative ? "-0x" : "0x", negative ? 3 : 2);
0 1 SV *hex = newSVpvn(negative ? "-0x" : "0x", negative ? 3 : 2);
1078 13 1 for (STRLEN i = 0; i < n; i++) {
1084 0 1 PUSHMARK(SP);
1085 0 1 XPUSHs(sv_2mortal(newSVpv("Math::BigInt", 0)));
1086 0 1 XPUSHs(sv_2mortal(hex));
1092 1 0 FREETMPS;
1100 13 1 for (STRLEN i = 0; i < n; i++) {
1103 0 1 if (negative) {
1105 0 0 for (STRLEN i = 0; i < n * 8; i++)
1117 0 5604 if (t == 0x28)
1119 5133 471 if (t == 0x29)
1122 453 18 if (t == 0xE0)
1124 18 0 if (t == 0xE4)
1146 0 15 if (items > 2) smile_croak(aTHX_ "encode_smile expects at most 2 arguments");
1147 10 5 if (items == 2) {
1149 7 3 if (SvOK(opts)) {
1150 7 0 if (!SvROK(opts) || SvTYPE(SvRV(opts)) != SVt_PVHV)
0 7 if (!SvROK(opts) || SvTYPE(SvRV(opts)) != SVt_PVHV)
1163 7 8 if (opts_hv) {
1165 9 5 while ((he = hv_iternext(opts_hv))) {
1166 0 9 const char *k = HePV(he, klen);
1168 4 5 if (klen == 12 && memEQ(k, "write_header", 12)) {
3 1 if (klen == 12 && memEQ(k, "write_header", 12)) {
1172 1 5 if (klen == 12 && memEQ(k, "shared_names", 12)) {
1 0 if (klen == 12 && memEQ(k, "shared_names", 12)) {
1176 2 3 if (klen == 13 && memEQ(k, "shared_values", 13)) {
2 0 if (klen == 13 && memEQ(k, "shared_values", 13)) {
1180 1 2 if (klen == 9 && memEQ(k, "canonical", 9)) {
1 0 if (klen == 9 && memEQ(k, "canonical", 9)) {
1188 3 10 if (!write_header) {
1189 2 1 if (!hv_exists(opts_hv, "shared_values", 13)) {
1194 10 3 if (write_header) {
1196 10 0 if (shared_names) h3 |= 0x01;
1197 9 1 if (shared_values) h3 |= 0x02;
1232 0 31 if (items > 2) smile_croak(aTHX_ "decode_smile expects at most 2 arguments");
1233 5 26 if (items == 2) {
1235 5 0 if (SvOK(opts)) {
1236 5 0 if (!SvROK(opts) || SvTYPE(SvRV(opts)) != SVt_PVHV)
0 5 if (!SvROK(opts) || SvTYPE(SvRV(opts)) != SVt_PVHV)
1256 31744 31 for (int i = 0; i < MAX_SHARED_NAMES; i++) ctx.seen_names[i] = NULL;
1257 31744 31 for (int i = 0; i < MAX_SHARED_VALUES; i++) ctx.seen_values[i] = NULL;
1259 5 26 if (opts_hv) {
1261 4 4 while ((he = hv_iternext(opts_hv))) {
1262 0 4 const char *k = HePV(he, klen);
1263 1 3 if (klen == 10 && memEQ(k, "use_bigint", 10)) {
1 0 if (klen == 10 && memEQ(k, "use_bigint", 10)) {
1268 2 1 if (klen == 14 && memEQ(k, "require_header", 14)) {
2 0 if (klen == 14 && memEQ(k, "require_header", 14)) {
1273 0 1 if (klen == 9 && memEQ(k, "json_bool", 9)) {
0 0 if (klen == 9 && memEQ(k, "json_bool", 9)) {
1282 30 0 if ((size_t)(r.end - r.p) >= 4 && r.p[0] == SMILE_HDR0 && r.p[1] == SMILE_HDR1 && r.p[2] == SMILE_HDR2) {
26 4 if ((size_t)(r.end - r.p) >= 4 && r.p[0] == SMILE_HDR0 && r.p[1] == SMILE_HDR1 && r.p[2] == SMILE_HDR2) {
26 0 if ((size_t)(r.end - r.p) >= 4 && r.p[0] == SMILE_HDR0 && r.p[1] == SMILE_HDR1 && r.p[2] == SMILE_HDR2) {
26 0 if ((size_t)(r.end - r.p) >= 4 && r.p[0] == SMILE_HDR0 && r.p[1] == SMILE_HDR1 && r.p[2] == SMILE_HDR2) {
1288 1 3 else if (require_header) {
1294 718 0 for (int i = 0; i < ctx.seen_name_count; i++) if (ctx.seen_names[i]) SvREFCNT_dec(ctx.seen_names[i]);
718 29 for (int i = 0; i < ctx.seen_name_count; i++) if (ctx.seen_names[i]) SvREFCNT_dec(ctx.seen_names[i]);
1295 2304 0 for (int i = 0; i < ctx.seen_value_count; i++) if (ctx.seen_values[i]) SvREFCNT_dec(ctx.seen_values[i]);
2304 29 for (int i = 0; i < ctx.seen_value_count; i++) if (ctx.seen_values[i]) SvREFCNT_dec(ctx.seen_values[i]);