Branch Coverage

secret_buffer_parse.c
Criterion Covered Total %
branch 397 594 66.8


line true false branch
24 6 96 if (looks_like_number(sv)) {
26 6 0 if (i < 0 || i > SECRET_BUFFER_ENCODING_MAX)
0 6 if (i < 0 || i > SECRET_BUFFER_ENCODING_MAX)
33 6 0 case 3: if (0 == strcmp(str, "HEX")) { enc= SECRET_BUFFER_ENCODING_HEX; break; }
34 1 0 case 4: if (0 == strcmp(str, "UTF8")) { enc= SECRET_BUFFER_ENCODING_UTF8; break; }
35 1 42 case 5: if (0 == strcmp(str, "ASCII")) { enc= SECRET_BUFFER_ENCODING_ASCII; break; }
36 42 0 if (0 == strcmp(str, "UTF-8")) { enc= SECRET_BUFFER_ENCODING_UTF8; break; }
37 26 0 case 6: if (0 == strcmp(str, "BASE64")) { enc= SECRET_BUFFER_ENCODING_BASE64; break; }
38 1 0 case 7: if (0 == strcmp(str, "UTF16LE")) { enc= SECRET_BUFFER_ENCODING_UTF16LE; break; }
39 0 0 if (0 == strcmp(str, "UTF16BE")) { enc= SECRET_BUFFER_ENCODING_UTF16BE; break; }
40 3 3 case 8: if (0 == strcmp(str, "UTF-16LE")) { enc= SECRET_BUFFER_ENCODING_UTF16LE; break; }
41 3 0 if (0 == strcmp(str, "UTF-16BE")) { enc= SECRET_BUFFER_ENCODING_UTF16BE; break; }
42 0 0 case 9: if (0 == strcmp(str, "ISO8859_1")) { enc= SECRET_BUFFER_ENCODING_ISO8859_1; break; }
43 13 0 case 10: if (0 == strcmp(str, "ISO-8859-1")) { enc= SECRET_BUFFER_ENCODING_ISO8859_1; break; }
48 102 0 if (out) *out= enc;
60 2265 1 if (lim > buf->len || pos > lim) {
0 2265 if (lim > buf->len || pos > lim) {
61 0 1 parse->error= pos > lim? "span starts beyond buffer" : "span ends beyond buffer";
78 1286 455 if ((span= secret_buffer_span_from_magic(sv, 0)) && SvTYPE(SvRV(sv)) == SVt_PVHV) {
1286 0 if ((span= secret_buffer_span_from_magic(sv, 0)) && SvTYPE(SvRV(sv)) == SVt_PVHV) {
84 2 453 else if ((sb= secret_buffer_from_magic(sv, 0))) {
88 453 0 else if (SvOK(sv)) {
113 609 439 if (rx) {
119 0 439 if (!secret_buffer_parse_init_from_sv(&pat_parse, pattern))
123 2 437 if (pat_parse.pos >= pat_parse.lim) {
124 0 2 if ((flags & SECRET_BUFFER_MATCH_REVERSE))
131 4 433 if (parse->pos >= parse->lim) {
138 17 416 if (pat_parse.encoding != SECRET_BUFFER_ENCODING_ISO8859_1) {
142 16 1 || pat_parse.encoding == SECRET_BUFFER_ENCODING_HEX
143 0 16 || pat_parse.encoding == SECRET_BUFFER_ENCODING_BASE64)
145 17 0 : SECRET_BUFFER_ENCODING_I32;
147 0 17 if (dst_len < 0)
152 17 0 if (pat_parse.encoding == SECRET_BUFFER_ENCODING_ASCII
156 16 1 || (pat_parse.encoding == SECRET_BUFFER_ENCODING_UTF8
157 9 7 && dst_len == (pat_parse.lim - pat_parse.pos) * 4)
165 0 8 if (!secret_buffer_parse_init(&pat_parse, tmp, 0, dst_len, dst_enc))
168 0 8 if (!secret_buffer_transcode(&pat_orig, (secret_buffer_parse_rw*) &pat_parse))
169 0 0 croak("transcode of pattern failed: %s", pat_orig.error? pat_orig.error : pat_parse.error);
177 426 7 if (pat_parse.encoding == SECRET_BUFFER_ENCODING_ISO8859_1) {
188 48 561 if (parse->pos >= parse->lim) // empty range
194 358 203 : sb_parse_match_charset_codepoints(parse, cset, flags);
210 24 94 if (dst_encoding == src->encoding && src->encoding == 0)
17 7 if (dst_encoding == src->encoding && src->encoding == 0)
220 758 101 while (tmp.pos < tmp.lim) {
222 0 758 if (cp < 0) return -1;
224 0 758 if (ch_size < 0) return -1;
228 10 91 if (dst_encoding == SECRET_BUFFER_ENCODING_BASE64) {
281 24 85 if (dst->encoding == src->encoding && src->encoding == 0) {
17 7 if (dst->encoding == src->encoding && src->encoding == 0) {
283 0 17 if (src->lim - src->pos != cnt) {
294 10 82 else if (dst->encoding == SECRET_BUFFER_ENCODING_BASE64) {
298 78 10 while (src->pos < src->lim) {
300 0 78 if (cp > 0xFF) {
304 24 54 if (!shift) {
306 0 24 if (dst->pos + 4 > dst->lim) {
324 5 5 if (dst->pos + (shift < 16? 4 : 0) != dst->lim) {
0 10 if (dst->pos + (shift < 16? 4 : 0) != dst->lim) {
329 5 5 if (shift < 16) {
331 0 5 if (dst->pos + 4 > dst->lim) {
338 1 4 writable[2] = shift? '=' : base64_alphabet[0x3F & (accum >> 6)];
343 444 82 while (src->pos < src->lim) {
345 0 444 if (cp < 0)
348 0 444 if (len < 0)
351 0 82 if (dst->pos != dst->lim) {
370 78 23 dst.encoding= encoding >= 0? encoding : src->encoding;
371 27 74 if (sv_isobject(dst_sv)) {
377 0 74 if (SvROK(dst_sv) && !sv_isobject(dst_sv) && SvTYPE(SvRV(dst_sv)) <= SVt_PVMG)
0 0 if (SvROK(dst_sv) && !sv_isobject(dst_sv) && SvTYPE(SvRV(dst_sv)) <= SVt_PVMG)
0 0 if (SvROK(dst_sv) && !sv_isobject(dst_sv) && SvTYPE(SvRV(dst_sv)) <= SVt_PVMG)
380 74 0 if (SvTYPE(dst_sv) > SVt_PVMG || SvROK(dst_sv)) {
0 74 if (SvTYPE(dst_sv) > SVt_PVMG || SvROK(dst_sv)) {
386 66 8 if (encoding < 0 && SECRET_BUFFER_ENCODING_IS_UNICODE(src->encoding)) {
64 2 if (encoding < 0 && SECRET_BUFFER_ENCODING_IS_UNICODE(src->encoding)) {
63 1 if (encoding < 0 && SECRET_BUFFER_ENCODING_IS_UNICODE(src->encoding)) {
62 1 if (encoding < 0 && SECRET_BUFFER_ENCODING_IS_UNICODE(src->encoding)) {
62 0 if (encoding < 0 && SECRET_BUFFER_ENCODING_IS_UNICODE(src->encoding)) {
393 0 101 if (need_bytes < 0)
396 27 74 if (dst_sbuf) {
400 20 7 if (!append)
412 72 2 if (!append)
415 66 8 if (dst_wide) SvPVutf8(dst_sv, len);
418 2 72 sv_grow(dst_sv, (append? len : 0) + need_bytes + 1);
425 0 101 if (!secret_buffer_transcode(src, &dst)) {
426 0 0 if (!src->error) src->error= dst.error;
430 27 74 if (dst_sbuf) {
435 0 74 SvSETMAGIC(dst_sv);
454 339 45 if (val > 127) {
457 1662 339 while (tmp) {
466 0 384 ASSUME(enc_len < 127);
469 45 339 if (val <= 127) {
474 1662 339 while (tmp) {
490 0 384 if (pos >= lim) {
499 339 45 if ((result & 0x80)) {
502 0 339 if (n == 0) {
509 0 339 if (n > sizeof(UV)) {
514 0 339 if ((size_t)(lim - pos) < (size_t)n) {
524 0 339 if (!result) {
529 1323 339 while (pos < lim)
532 0 339 if (result < 0x80) {
537 384 0 if (out) *out = result;
556 1539 384 while (tmp) {
567 1539 384 if (tmp)
570 1539 384 } while (tmp);
571 0 384 ASSUME(pos == (U8*)(buf->data + buf->len));
582 0 384 if (pos >= lim) {
588 1539 384 while (*pos++ & 0x80) {
589 0 1539 if (pos >= lim) {
594 3 1536 if (shift > sizeof(UV)*8 - 7) {
596 3 0 if (shift >= sizeof(UV)*8 || (payload >> (sizeof(UV)*8 - shift))) {
0 3 if (shift >= sizeof(UV)*8 || (payload >> (sizeof(UV)*8 - shift))) {
605 3 381 if (!payload && result != 0) {
0 3 if (!payload && result != 0) {
609 384 0 if (out) *out = result;
628 1539 387 while (tmp) {
635 1926 387 for (shift= (enc_len-1) * 7; shift >= 0; shift -= 7) {
637 1539 387 if (shift)
641 0 387 ASSUME(pos == (U8*)(buf->data + buf->len));
651 0 395 if (pos >= lim) {
656 0 395 if (*pos == 0x80) {
661 1539 395 while (*pos++ & 0x80) {
663 0 1539 if (result >> (sizeof(UV)*8 - 7)) {
667 0 1539 if (pos >= lim) {
673 395 0 if (out) *out = result;
689 355 3 bool multi= 0 != (flags & SECRET_BUFFER_MATCH_MULTI) || cset->match_multi;
223 132 bool multi= 0 != (flags & SECRET_BUFFER_MATCH_MULTI) || cset->match_multi;
692 86 272 int step= reverse? -1 : 1;
693 86 272 const U8 *pos= reverse? parse->lim-1 : parse->pos,
694 86 272 *lim= reverse? parse->pos-1 : parse->lim,
698 1166 58 while (pos != lim) {
699 250 916 if (sbc_bitmap_test(cset->bitmap, *pos) != negate) {
701 105 145 if (span_start)
704 39 106 if (!multi) {
709 788 128 } else if (anchored && !span_start)
156 632 } else if (anchored && !span_start)
716 0 358 if (consttime) {
718 0 0 while (pos != lim) {
725 86 272 if (reverse) {
727 21 65 parse->lim= span_start? span_start + 1 : parse->pos;
730 148 124 parse->pos= span_start? span_start : parse->lim;
743 203 0 bool multi= 0 != (flags & SECRET_BUFFER_MATCH_MULTI) || cset->match_multi;
2 201 bool multi= 0 != (flags & SECRET_BUFFER_MATCH_MULTI) || cset->match_multi;
748 5 198 const U8 *span_mark= NULL, *prev_mark= reverse? parse->lim : parse->pos;
750 231 0 while (parse->pos < parse->lim) {
752 19 212 : sb_parse_next_codepoint(parse);
754 7 224 if (codepoint < 0) {// encoding error
758 198 26 if (sbc_test_codepoint(aTHX_ cset, codepoint) != negate) {
761 2 196 if (span_started)
766 194 2 if (!multi) {
767 4 190 prev_mark= reverse? parse->lim : parse->pos;
770 0 26 } else if (anchored && !span_started)
0 0 } else if (anchored && !span_started)
772 14 14 prev_mark= reverse? parse->lim : parse->pos;
777 0 203 if (consttime) {
779 0 0 while (parse->pos < parse->lim) {
781 0 0 : sb_parse_next_codepoint(parse);
783 0 0 if (codepoint < 0) { // encoding error
792 7 196 if (encoding_error)
795 196 0 if (span_started) { // and implicitly ends span
796 5 191 if (reverse) {
813 91 20 while (lhs->pos < lhs->lim && rhs->pos < rhs->lim) {
91 0 while (lhs->pos < lhs->lim && rhs->pos < rhs->lim) {
815 0 91 if (lhs_cp < 0)
818 0 91 if (rhs_cp < 0)
820 2 89 if (lhs_cp != rhs_cp && !ret)
2 0 if (lhs_cp != rhs_cp && !ret)
821 2 0 ret= lhs_cp < rhs_cp? -1 : 1;
824 18 2 : (lhs->pos < lhs->lim)? 1 /* right string shorter than left */
825 18 0 : (rhs->pos < rhs->lim)? -1 /* left string shorter than right */
826 0 18 : 0;
835 3606 1 if (encoding == SECRET_BUFFER_ENCODING_ASCII
836 815 2791 || encoding == SECRET_BUFFER_ENCODING_ISO8859_1
837 573 242 || encoding == SECRET_BUFFER_ENCODING_UTF8
839 0 3365 if (lim - pos < 1)
842 145 3220 if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_ASCII)
1 144 if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_ASCII)
844 144 3220 else if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_UTF8) {
73 71 else if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_UTF8) {
848 0 13 { if (lim - pos < 3) goto incomplete;
852 0 13 if ((*pos & 0xC0) != 0x80) goto invalid;
856 4 20 { if (lim - pos < 2) goto incomplete;
860 0 33 if ((*pos & 0xC0) != 0x80) goto invalid;
864 2 34 { if (lim - pos < 1) goto incomplete;
868 0 67 if ((*pos & 0xC0) != 0x80) goto invalid;
875 0 67 if (cp < min_cp)
877 0 67 else if (cp > 0x10FFFF)
882 221 21 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
883 15 206 || encoding == SECRET_BUFFER_ENCODING_UTF16BE
886 0 36 if (lim - pos < 2)
890 10 26 if (cp >= 0xD800 && cp <= 0xDFFF) {
10 0 if (cp >= 0xD800 && cp <= 0xDFFF) {
891 0 10 if (lim - pos < 2)
895 10 0 if (w2 < 0xDC00 || w2 > 0xDFFF)
0 10 if (w2 < 0xDC00 || w2 > 0xDFFF)
900 38 168 else if (encoding == SECRET_BUFFER_ENCODING_HEX) {
902 38 0 while (pos < lim && isspace(*pos))
0 38 while (pos < lim && isspace(*pos))
904 0 38 if (lim - pos < 2)
908 0 38 if (low >= ('a'-'0')) low -= ('a'-'0'-10);
909 8 30 else if (low >= ('A'-'0')) low -= ('A'-'0'-10);
910 0 38 if (high >= ('a'-'0')) high -= ('a'-'0'-10);
911 8 30 else if (high >= ('A'-'0')) high -= ('A'-'0'-10);
912 0 38 if ((low >> 4) | (high >> 4))
917 30 8 while (pos < lim && isspace(*pos))
0 30 while (pos < lim && isspace(*pos))
920 168 0 else if (encoding == SECRET_BUFFER_ENCODING_BASE64) {
922 168 0 while (pos < lim && *pos <= ' ')
0 168 while (pos < lim && *pos <= ' ')
925 168 0 if (pos < lim) {
926 0 168 if (base64_decode_table[*pos] < 0)
931 168 0 while (pos < lim && *pos <= ' ')
0 168 while (pos < lim && *pos <= ' ')
934 0 168 if (pos >= lim) {
938 0 168 if (base64_decode_table[*pos] < 0)
943 51 117 if (parse->pos_bit >= 6) {
947 47 8 while (pos < lim && *pos <= ' ')
4 43 while (pos < lim && *pos <= ' ')
953 117 0 while (next < lim && *next <= ' ')
0 117 while (next < lim && *next <= ' ')
955 117 0 if (next < lim && *next == '=') {
13 104 if (next < lim && *next == '=') {
961 0 0 else if (encoding == SECRET_BUFFER_ENCODING_I32) {
962 0 0 if (lim - pos < 4)
979 850 0 if (encoding == SECRET_BUFFER_ENCODING_ASCII
980 25 825 || encoding == SECRET_BUFFER_ENCODING_ISO8859_1
981 17 8 || encoding == SECRET_BUFFER_ENCODING_UTF8
983 0 842 if (lim <= pos)
987 4 838 if (cp >= 0x80 && encoding != SECRET_BUFFER_ENCODING_ISO8859_1) {
4 0 if (cp >= 0x80 && encoding != SECRET_BUFFER_ENCODING_ISO8859_1) {
989 0 4 if (encoding == SECRET_BUFFER_ENCODING_ASCII)
993 12 0 while (start >= pos && (*start & 0xC0) == 0x80)
8 4 while (start >= pos && (*start & 0xC0) == 0x80)
997 0 4 if (parse->pos != parse->lim) {// consumed all characters we gave it?
999 0 0 if (cp >= 0) // had a valid char, but extra 0x80 bytes
1008 8 0 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
1009 1 7 || encoding == SECRET_BUFFER_ENCODING_UTF16BE
1011 0 1 if (lim - pos < 2)
1017 1 0 if (cp >= 0xD800 && cp <= 0xDFFF) {
1 0 if (cp >= 0xD800 && cp <= 0xDFFF) {
1018 0 1 if (lim - pos < 4)
1022 1 0 if (w1 < 0xD800 || w1 > 0xDFFF || cp < 0xDC00)
1 0 if (w1 < 0xD800 || w1 > 0xDFFF || cp < 0xDC00)
0 1 if (w1 < 0xD800 || w1 > 0xDFFF || cp < 0xDC00)
1027 1 6 else if (encoding == SECRET_BUFFER_ENCODING_HEX) {
1029 1 0 while (pos < lim && isspace(lim[-1]))
0 1 while (pos < lim && isspace(lim[-1]))
1031 0 1 if (lim - pos < 2)
1032 0 0 SB_RETURN_ERROR((pos == lim? "end of span" : "incomplete hex pair at end of span"))
1035 1 0 if (low >= ('a'-'0')) low -= ('a'-'0'-10);
1036 0 0 else if (low >= ('A'-'0')) low -= ('A'-'0'-10);
1037 1 0 if (high >= ('a'-'0')) high -= ('a'-'0'-10);
1038 0 0 else if (high >= ('A'-'0')) high -= ('A'-'0'-10);
1039 0 1 if ((low >> 4) | (high >> 4))
1043 6 0 else if (encoding == SECRET_BUFFER_ENCODING_BASE64) {
1048 12 0 while (pos < lim && base64_decode_table[lim[-1]] < 0)
3 9 while (pos < lim && base64_decode_table[lim[-1]] < 0)
1050 9 0 if (pos < lim) {
1052 0 9 if (base64_decode_table[lim[-1]] < 0)
1058 3 6 if (lim[-1] == '=')
1062 9 0 while (pos < lim && base64_decode_table[lim[-1]] < 0)
0 9 while (pos < lim && base64_decode_table[lim[-1]] < 0)
1065 0 9 if (pos >= lim) {
1069 0 9 if (base64_decode_table[lim[-1]] < 0)
1074 3 6 if (parse->lim_bit >= 6) {
1079 0 3 while (pos < lim && base64_decode_table[lim[-1]] < 0)
0 0 while (pos < lim && base64_decode_table[lim[-1]] < 0)
1083 3 6 } while (again);
1085 0 0 else if (encoding == SECRET_BUFFER_ENCODING_I32) {
1086 0 0 if (lim - pos < 4)
1098 0 1202 if (encoding == SECRET_BUFFER_ENCODING_ASCII)
1099 0 0 return codepoint < 0x80? 1 : -1;
1100 110 1092 if (encoding == SECRET_BUFFER_ENCODING_ISO8859_1)
1101 110 0 return codepoint < 0x100? 1 : -1;
1102 736 356 else if (encoding == SECRET_BUFFER_ENCODING_UTF8)
1103 44 692 return codepoint < 0x80? 1 : codepoint < 0x800? 2 : codepoint < 0x10000? 3 : 4;
24 20 return codepoint < 0x80? 1 : codepoint < 0x800? 2 : codepoint < 0x10000? 3 : 4;
8 16 return codepoint < 0x80? 1 : codepoint < 0x800? 2 : codepoint < 0x10000? 3 : 4;
1104 356 0 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
1105 0 356 || encoding == SECRET_BUFFER_ENCODING_UTF16BE)
1106 0 0 return codepoint >= 0xD800 && codepoint < 0xE000? -1
1107 0 0 : codepoint < 0x10000? 2 : 4;
0 0 : codepoint < 0x10000? 2 : 4;
1108 6 350 else if (encoding == SECRET_BUFFER_ENCODING_HEX)
1109 6 0 return codepoint < 0x100? 2 : -1;
1111 78 272 else if (encoding == SECRET_BUFFER_ENCODING_BASE64)
1112 78 0 return codepoint < 0x100? 1 : -1;
1113 272 0 else if (encoding == SECRET_BUFFER_ENCODING_I32)
1124 0 444 if (codepoint >= 0x110000)
1128 0 444 if (n < 0)
1130 0 444 if (dst->lim - dst_pos < n)
1134 444 0 if (encoding == SECRET_BUFFER_ENCODING_ASCII
1135 389 55 || encoding == SECRET_BUFFER_ENCODING_ISO8859_1
1136 368 21 || encoding == SECRET_BUFFER_ENCODING_UTF8
1155 21 0 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
1156 0 21 || encoding == SECRET_BUFFER_ENCODING_UTF16BE
1159 0 0 if (n == 2) {
1173 3 18 else if (encoding == SECRET_BUFFER_ENCODING_HEX) {
1177 18 0 else if (encoding == SECRET_BUFFER_ENCODING_I32) {