Branch Coverage

SecretBuffer.xs
Criterion Covered Total %
branch 329 510 64.5


line true false branch
53 20 382 if (ofs < 0) {
55 0 20 if (ofs < 0)
58 10 372 else if (ofs > len)
66 1150 0 SvUPGRADE(name, SVt_PVNV);
113 125 0 return (pagesize < 0)? 4096 : pagesize;
224 11224 0 if ((!obj || !SvOK(obj)) && (flags & SECRET_BUFFER_MAGIC_UNDEF_OK))
0 11224 if ((!obj || !SvOK(obj)) && (flags & SECRET_BUFFER_MAGIC_UNDEF_OK))
0 0 if ((!obj || !SvOK(obj)) && (flags & SECRET_BUFFER_MAGIC_UNDEF_OK))
227 1510 9714 if (!sv_isobject(obj)) {
228 0 1510 if (flags & SECRET_BUFFER_MAGIC_OR_DIE)
233 8351 1363 if (SvMAGICAL(sv) && (magic = mg_findext(sv, PERL_MAGIC_ext, mg_vtbl)))
7836 515 if (SvMAGICAL(sv) && (magic = mg_findext(sv, PERL_MAGIC_ext, mg_vtbl)))
236 1363 515 if (flags & SECRET_BUFFER_MAGIC_AUTOCREATE && auto_ctor) {
1363 0 if (flags & SECRET_BUFFER_MAGIC_AUTOCREATE && auto_ctor) {
244 0 515 if (flags & SECRET_BUFFER_MAGIC_OR_DIE)
268 566 0 if (buf) {
270 31 535 if (buf->stringify_sv)
304 64 1 if (buf->data) {
306 0 64 if (buf->capacity <= buf->len) {
342 31 23 if (!sv) {
362 1 0 if (!sv || !SvOK(sv))
0 1 if (!sv || !SvOK(sv))
364 1 0 if (SvIOK(sv))
366 0 0 if (SvPOK(sv)) {
368 0 0 if (!str[0]) return 0;
369 0 0 if (strcmp(str, "NONBLOCK") == 0) return SECRET_BUFFER_NONBLOCK;
375 2 0 if (!sv || !SvOK(sv))
0 2 if (!sv || !SvOK(sv))
377 0 2 if (SvIOK(sv))
379 2 0 if (SvPOK(sv)) {
381 0 2 if (!str[0]) return 0;
382 2 0 if (strcmp(str, "AT_LEAST") == 0) return SECRET_BUFFER_AT_LEAST;
393 0 0 if (sv && SvIOK(sv)) {
0 0 if (sv && SvIOK(sv)) {
395 0 0 if (val < 1 || val > 3)
0 0 if (val < 1 || val > 3)
398 0 0 } else if (sv && SvOK(sv)) {
0 0 } else if (sv && SvOK(sv)) {
401 0 0 if (strcmp(str, "BASE128LE") == 0) return BASE128LE;
402 0 0 if (strcmp(str, "BASE128BE") == 0) return BASE128BE;
403 0 0 if (strcmp(str, "ASN1_DER_LENGTH") == 0) return ASN1_DER_LENGTH;
449 124 125 while (p < lim) {
451 124 0 while (p < lim && !is_page_accessible(p)) {
0 124 while (p < lim && !is_page_accessible(p)) {
456 28653 124 while (p < lim && is_page_accessible(p)) {
28653 0 while (p < lim && is_page_accessible(p)) {
461 131 0 while (run_start < run_lim && (at= memmem((void*)run_start, run_lim - run_start, needle, needle_len))) {
7 124 while (run_start < run_lim && (at= memmem((void*)run_start, run_lim - run_start, needle, needle_len))) {
490 110 423 if (items - next_arg == 1) {
494 0 423 if ((items - next_arg) & 1)
496 5 423 for (i= next_arg; i < items-1; i += 2) {
502 0 5 PUSHMARK(SP);
503 0 5 EXTEND(SP, 2);
508 5 0 FREETMPS;
522 29 1 size_t from_ofs= (ix? 0 : buf->len), len_sum= 0;
525 0 30 if ((items-1) > 16) {
530 30 30 for (i= 0; i < items-1; i++) {
536 30 30 for (i= 0; i < items-1; i++) {
547 4 67 if (val) { /* writing */
549 0 4 if (ival < 0) ival= 0;
563 4 4 if (val) { /* wiritng */
565 0 4 if (ival < 0) ival= 0;
566 2 2 if (flags & SECRET_BUFFER_AT_LEAST)
594 20 9 if (ix == 0) { // index (forward)
595 7 13 pos= normalize_offset(SvOK(ofs_sv)? SvIV(ofs_sv) : 0, buf->len);
598 4 5 IV max= normalize_offset(SvOK(ofs_sv)? SvIV(ofs_sv) : -1, buf->len);
603 2 7 if (SvRX(pattern))
611 2 7 if (lim > buf->len) lim= buf->len;
613 0 29 if (!secret_buffer_parse_init(&parse, buf, pos, lim, 0))
616 25 4 if (secret_buffer_match(&parse, pattern, flags))
619 0 4 if (parse.error)
637 106 0 IV len= !SvOK(len_sv)? buf->len : SvIV(len_sv);
639 0 106 if (!secret_buffer_parse_init(&parse, buf,
645 82 24 if (secret_buffer_match(&parse, pattern, flags)) {
649 0 24 else if (parse.error)
676 14 4 IV count= count_sv? SvIV(count_sv) : buf->len;
684 11 7 if (GIMME_V != G_VOID) {
687 8 3 if (count) {
693 1 10 if (el && *el)
1 0 if (el && *el)
698 7 11 if (replacement)
701 7 11 if (!sub_ref)
737 3 1 for (i= 1; i < items; i++) {
745 3 1 for (i= 1; i < items; i++) {
773 1252 163 for (i = 0; i < common_len; i++)
774 8 1244 if (lhs_buf[i] != rhs_buf[i] && !ret)
8 0 if (lhs_buf[i] != rhs_buf[i] && !ret)
775 4 4 ret= lhs_buf[i] < rhs_buf[i]? -1 : 1;
776 155 8 if (ret == 0 && lhs_len != rhs_len)
6 149 if (ret == 0 && lhs_len != rhs_len)
777 3 3 ret= lhs_len < rhs_len? -1 : 1;
780 4 159 if (reverse)
791 0 2 RETVAL= secret_buffer_append_random(buf, count, flags);
804 6 0 ST(0)= (got < 0)? &PL_sv_undef : sv_2mortal(newSViv(got));
816 3 1 ST(0)= (got < 0)? &PL_sv_undef : sv_2mortal(newSViv(got));
828 5 17 : got == SECRET_BUFFER_EOF? &PL_sv_no
829 3 2 : &PL_sv_undef;
842 4 0 ST(0)= (wrote < 0)? &PL_sv_undef : sv_2mortal(newSViv(wrote));
855 1 2 wrote= secret_buffer_write_async(buf, io, ofs, count, GIMME_V == G_VOID? NULL : &ref_out);
858 3 0 ST(0)= wrote? sv_2mortal(newSViv(wrote)) : ref_out? ref_out : &PL_sv_undef;
0 0 ST(0)= wrote? sv_2mortal(newSViv(wrote)) : ref_out? ref_out : &PL_sv_undef;
867 43 12 if (!field || !*field) {
0 43 if (!field || !*field) {
869 3 40 } else if (SvOK(*field)) {
883 0 7 PUSHMARK(SP);
884 0 7 EXTEND(SP, 1);
894 0 0 RETVAL= false;
904 0 125 if (!buf->len)
907 0 125 if (RETVAL < 0)
921 0 7 PUSHMARK(SP);
922 7 0 EXTEND(SP, items);
0 7 EXTEND(SP, items);
923 11 7 for (i= 1; i < items; i++) {
924 11 0 if (SvOK(ST(i)) && SvROK(ST(i)) && (buf= secret_buffer_from_magic(ST(i), 0)))
7 4 if (SvOK(ST(i)) && SvROK(ST(i)) && (buf= secret_buffer_from_magic(ST(i), 0)))
7 0 if (SvOK(ST(i)) && SvROK(ST(i)) && (buf= secret_buffer_from_magic(ST(i), 0)))
953 0 0 if (secret_buffer_async_result_recv(result, (IV)(timeout*1000), &bytes_written, &os_err)) {
954 0 0 EXTEND(sp, 2);
977 0 22 if (items == 2) {
979 0 0 handle= io? IoIFP(io) : NULL;
980 22 0 } else if (items > 2) {
982 0 22 if ((items - 1) & 1)
984 66 22 for (; i < items; i+= 2) {
987 22 44 if (len == 4 && memcmp(name, "echo", 4) == 0) {
22 0 if (len == 4 && memcmp(name, "echo", 4) == 0) {
990 22 22 else if (len == 6 && memcmp(name, "handle", 6) == 0) {
22 0 else if (len == 6 && memcmp(name, "handle", 6) == 0) {
992 22 0 handle= io? IoIFP(io) : NULL;
994 0 22 else if (len == 10 && memcmp(name, "line_input", 10) == 0) {
0 0 else if (len == 10 && memcmp(name, "line_input", 10) == 0) {
997 22 0 else if (len == 12 && memcmp(name, "auto_restore", 12) == 0) {
22 0 else if (len == 12 && memcmp(name, "auto_restore", 12) == 0) {
1005 0 22 if (!handle)
1010 22 0 if (!sb_console_state_init(aTHX_ &cstate, handle)) {
1011 0 22 if (ix == 0)
1015 0 0 if (auto_restore)
1017 0 0 if (set_echo && SvOK(set_echo)) {
0 0 if (set_echo && SvOK(set_echo)) {
1019 0 0 if (sb_console_state_get_echo(&cstate) != enable) {
1021 0 0 if (!sb_console_state_set_echo(&cstate, enable))
1025 0 0 if (set_line_input && SvOK(set_line_input)) {
0 0 if (set_line_input && SvOK(set_line_input)) {
1027 0 0 if (sb_console_state_get_line_input(&cstate) != enable) {
1029 0 0 if (!sb_console_state_set_line_input(&cstate, enable))
1035 0 0 if (ix == 1 && already_set)
0 0 if (ix == 1 && already_set)
1052 0 0 if (enable != NULL)
1063 0 0 if (enable != NULL)
1074 0 0 if (enable != NULL)
1076 0 0 RETVAL= cstate->auto_restore;
1085 0 0 cstate->auto_restore= false; /* no longer run restore on destructor */
1101 56 0 SV **buf_field= span && SvTYPE(SvRV(class_or_obj)) == SVt_PVHV
1103 56 498 : NULL;
1104 56 498 secret_buffer *buf= secret_buffer_from_magic(
1107 56 498 bool subspan= span && ix >= 2;
8 48 bool subspan= span && ix >= 2;
1108 8 546 IV base_pos= subspan? span->pos : 0;
1110 56 498 int encoding= span? span->encoding : 0, i;
1116 550 4 if (buf && items >= 2 && looks_like_number(ST(1))) {
86 464 if (buf && items >= 2 && looks_like_number(ST(1))) {
29 57 if (buf && items >= 2 && looks_like_number(ST(1))) {
1119 26 3 if (items >= 3 && SvOK(ST(2))) {
26 0 if (items >= 3 && SvOK(ST(2))) {
1122 2 24 if (items >= 4) {
1124 0 2 if (items > 4)
1129 0 525 if ((items - 1) & 1)
1131 84 525 for (i= 1; i < items-1; i += 2) {
1132 22 62 if (0 == strcmp("pos", SvPV_nolen(ST(i)))) {
1136 30 32 else if (0 == strcmp("lim", SvPV_nolen(ST(i)))) {
1140 4 28 else if (0 == strcmp("len", SvPV_nolen(ST(i)))) {
1144 26 2 else if (0 == strcmp("encoding", SvPV_nolen(ST(i)))) {
1147 2 0 else if (0 == strcmp("buf", SvPV_nolen(ST(i)))) {
1152 30 524 if (have_len && have_lim && (lim != pos + len))
0 30 if (have_len && have_lim && (lim != pos + len))
0 0 if (have_len && have_lim && (lim != pos + len))
1155 2 552 if (!buf) {
1157 0 2 if (ix != 4)
1162 8 546 base_lim= subspan? span->lim : buf->len;
1165 51 503 : span ? span->pos
42 461 : span ? span->pos
1169 30 524 : have_len? normalize_offset(len, base_lim-pos)+pos
30 494 : have_len? normalize_offset(len, base_lim-pos)+pos
32 462 : have_len? normalize_offset(len, base_lim-pos)+pos
1172 0 554 if (pos > lim)
1176 28 526 if (encoding_sv) {
1177 0 28 if (!parse_encoding(aTHX_ encoding_sv, &encoding))
1191 74 368 if (newval_sv) {
1193 0 74 if (newval < 0)
1197 0 10 case 1: if (newval < span->pos) croak("lim must be >= pos");
1203 319 123 RETVAL= ix == 0? span->pos
1204 181 261 : ix == 1? span->lim
1205 76 185 : ix == 2? span->lim - span->pos
1206 185 0 : -1;
1217 0 26 if (!encodings) croak("BUG");
1219 15 11 if (newval_sv)
1220 0 15 if (!parse_encoding(aTHX_ newval_sv, &span->encoding))
1223 26 0 if (!enc_const || !SvOK(enc_const))
0 26 if (!enc_const || !SvOK(enc_const))
1243 0 3 if (!secret_buffer_parse_init_from_sv(&p, self))
1247 3 0 if (p.lim - p.pos >= 3 && p.pos[0] == 0xEF && p.pos[1] == 0xBB && p.pos[2] == 0xBF) {
1 2 if (p.lim - p.pos >= 3 && p.pos[0] == 0xEF && p.pos[1] == 0xBB && p.pos[2] == 0xBF) {
1 0 if (p.lim - p.pos >= 3 && p.pos[0] == 0xEF && p.pos[1] == 0xBB && p.pos[2] == 0xBF) {
1 0 if (p.lim - p.pos >= 3 && p.pos[0] == 0xEF && p.pos[1] == 0xBB && p.pos[2] == 0xBF) {
1251 2 0 else if (p.lim - p.pos >= 2 && p.pos[0] == 0xFF && p.pos[1] == 0xFE) {
1 1 else if (p.lim - p.pos >= 2 && p.pos[0] == 0xFF && p.pos[1] == 0xFE) {
1 0 else if (p.lim - p.pos >= 2 && p.pos[0] == 0xFF && p.pos[1] == 0xFE) {
1255 1 0 else if (p.lim - p.pos >= 2 && p.pos[0] == 0xFE && p.pos[1] == 0xFF) {
1 0 else if (p.lim - p.pos >= 2 && p.pos[0] == 0xFE && p.pos[1] == 0xFF) {
1 0 else if (p.lim - p.pos >= 2 && p.pos[0] == 0xFE && p.pos[1] == 0xFF) {
1279 0 572 if (!secret_buffer_parse_init(&parse, buf, span->pos, span->lim, span->encoding))
1282 68 504 if (ix & 1)
1285 526 46 if (ix & 2)
1292 470 102 if (ret_type != 1 && parse.encoding == SECRET_BUFFER_ENCODING_BASE64)
0 470 if (ret_type != 1 && parse.encoding == SECRET_BUFFER_ENCODING_BASE64)
1296 14 558 if (!pattern) {
1297 2 12 if (op == 3 || op == 4 || op == 5)
1 1 if (op == 3 || op == 4 || op == 5)
1 0 if (op == 3 || op == 4 || op == 5)
1299 0 14 if (!pattern)
1304 1 571 if (parse.error)
1308 197 67 if (matched) span->pos= parse.lim - (U8*) buf->data;
1311 1 0 if (matched) span->lim= parse.pos - (U8*) buf->data;
1315 39 79 if (matched) span->pos= parse.lim - (U8*) buf->data;
1316 40 78 if (op == 4) break;
1323 19 100 if (matched) span->lim= parse.pos - (U8*) buf->data;
1328 311 260 if (ret_type == 0) {
1329 77 234 if (!matched)
1331 234 0 if (parse.pos > parse.lim || parse.lim > (U8*) buf->data + buf->len)
0 234 if (parse.pos > parse.lim || parse.lim > (U8*) buf->data + buf->len)
1335 101 159 } else if (ret_type == 1) {
1336 63 38 if (matched)
1355 0 5 if (!secret_buffer_parse_init_from_sv(&p, self))
1358 12 2 while (count && p.pos < p.lim) {
11 1 while (count && p.pos < p.lim) {
1359 0 11 if (!secret_buffer_parse_uv_base128be(&p, &len)) {
1363 2 9 if (len > p.lim - p.pos) {
1368 0 9 XPUSHs(secret_buffer_span_new_obj(p.sbuf, ofs, ofs + len, 0));
1370 4 5 if (count > 0) --count;
1387 0 1152 if (!secret_buffer_parse_init_from_sv(&p, self))
1396 1152 0 if (success) {
1418 1 101 if (!secret_buffer_parse_init_from_sv(&src, self))
1421 89 12 if (ix > 0) { /* called as 'copy_to' or 'append_to' */
1422 0 89 if (items < 2)
1433 0 101 if ((items - next_arg) & 1)
1435 23 101 for (; next_arg < items; next_arg+= 2) {
1436 23 0 if (0 == strcmp(SvPV_nolen(ST(next_arg)), "encoding")) {
1437 0 23 if (!parse_encoding(aTHX_ ST(next_arg+1), &dst_encoding))
1441 0 101 if (!secret_buffer_copy_to(&src, dst_sv, dst_encoding, ix == 2))
1444 12 89 if (ix == 0)
1454 0 18 if (!secret_buffer_parse_init_from_sv(&lhs_parse, lhs))
1456 0 18 if (!secret_buffer_parse_init_from_sv(&rhs_parse, rhs))
1460 0 18 if (reverse)
1496 184 23 for (i= 0; i <= SECRET_BUFFER_ENCODING_MAX; i++)
1497 161 23 if (enc[i] && av_store(encodings, i, enc[i]))
161 0 if (enc[i] && av_store(encodings, i, enc[i]))