Branch Coverage

secret_buffer_parse.c
Criterion Covered Total %
branch 391 592 66.0


line true false branch
18 0 66 if (looks_like_number(sv)) {
20 0 0 if (i < 0 || i > SECRET_BUFFER_ENCODING_MAX)
0 0 if (i < 0 || i > SECRET_BUFFER_ENCODING_MAX)
27 6 0 case 3: if (0 == strcmp(str, "HEX")) { enc= SECRET_BUFFER_ENCODING_HEX; break; }
28 1 0 case 4: if (0 == strcmp(str, "UTF8")) { enc= SECRET_BUFFER_ENCODING_UTF8; break; }
29 1 12 case 5: if (0 == strcmp(str, "ASCII")) { enc= SECRET_BUFFER_ENCODING_ASCII; break; }
30 12 0 if (0 == strcmp(str, "UTF-8")) { enc= SECRET_BUFFER_ENCODING_UTF8; break; }
31 26 0 case 6: if (0 == strcmp(str, "BASE64")) { enc= SECRET_BUFFER_ENCODING_BASE64; break; }
32 1 0 case 7: if (0 == strcmp(str, "UTF16LE")) { enc= SECRET_BUFFER_ENCODING_UTF16LE; break; }
33 0 0 if (0 == strcmp(str, "UTF16BE")) { enc= SECRET_BUFFER_ENCODING_UTF16BE; break; }
34 3 3 case 8: if (0 == strcmp(str, "UTF-16LE")) { enc= SECRET_BUFFER_ENCODING_UTF16LE; break; }
35 3 0 if (0 == strcmp(str, "UTF-16BE")) { enc= SECRET_BUFFER_ENCODING_UTF16BE; break; }
36 0 0 case 9: if (0 == strcmp(str, "ISO8859_1")) { enc= SECRET_BUFFER_ENCODING_ISO8859_1; break; }
37 13 0 case 10: if (0 == strcmp(str, "ISO-8859-1")) { enc= SECRET_BUFFER_ENCODING_ISO8859_1; break; }
42 66 0 if (out) *out= enc;
54 2000 1 if (lim > buf->len || pos > lim) {
0 2000 if (lim > buf->len || pos > lim) {
55 0 1 parse->error= pos > lim? "span starts beyond buffer" : "span ends beyond buffer";
72 1284 453 if ((span= secret_buffer_span_from_magic(sv, 0)) && SvTYPE(SvRV(sv)) == SVt_PVHV) {
1284 0 if ((span= secret_buffer_span_from_magic(sv, 0)) && SvTYPE(SvRV(sv)) == SVt_PVHV) {
78 2 451 else if ((sb= secret_buffer_from_magic(sv, 0))) {
82 451 0 else if (SvOK(sv)) {
107 346 439 if (rx) {
113 0 439 if (!secret_buffer_parse_init_from_sv(&pat_parse, pattern))
117 2 437 if (pat_parse.pos >= pat_parse.lim) {
118 0 2 if ((flags & SECRET_BUFFER_MATCH_REVERSE))
125 4 433 if (parse->pos >= parse->lim) {
132 17 416 if (pat_parse.encoding != SECRET_BUFFER_ENCODING_ISO8859_1) {
136 16 1 || pat_parse.encoding == SECRET_BUFFER_ENCODING_HEX
137 0 16 || pat_parse.encoding == SECRET_BUFFER_ENCODING_BASE64)
139 17 0 : SECRET_BUFFER_ENCODING_I32;
141 0 17 if (dst_len < 0)
146 17 0 if (pat_parse.encoding == SECRET_BUFFER_ENCODING_ASCII
150 16 1 || (pat_parse.encoding == SECRET_BUFFER_ENCODING_UTF8
151 9 7 && dst_len == (pat_parse.lim - pat_parse.pos) * 4)
159 0 8 if (!secret_buffer_parse_init(&pat_parse, tmp, 0, dst_len, dst_enc))
162 0 8 if (!secret_buffer_transcode(&pat_orig, &pat_parse))
163 0 0 croak("transcode of pattern failed: %s", pat_orig.error? pat_orig.error : pat_parse.error);
171 426 7 if (pat_parse.encoding == SECRET_BUFFER_ENCODING_ISO8859_1) {
182 48 298 if (parse->pos >= parse->lim) // empty range
188 289 9 : sb_parse_match_charset_codepoints(parse, cset, flags);
204 24 94 if (dst_encoding == src->encoding && src->encoding == 0)
17 7 if (dst_encoding == src->encoding && src->encoding == 0)
214 758 101 while (tmp.pos < tmp.lim) {
216 0 758 if (cp < 0) return -1;
218 0 758 if (ch_size < 0) return -1;
222 10 91 if (dst_encoding == SECRET_BUFFER_ENCODING_BASE64) {
275 24 85 if (dst->encoding == src->encoding && src->encoding == 0) {
17 7 if (dst->encoding == src->encoding && src->encoding == 0) {
277 0 17 if (src->lim - src->pos != cnt) {
288 10 82 else if (dst->encoding == SECRET_BUFFER_ENCODING_BASE64) {
292 78 10 while (src->pos < src->lim) {
294 0 78 if (cp > 0xFF) {
298 24 54 if (!shift) {
299 0 24 if (dst->pos + 4 > dst->lim) {
316 5 5 if (dst->pos + (shift < 16? 4 : 0) != dst->lim) {
0 10 if (dst->pos + (shift < 16? 4 : 0) != dst->lim) {
321 5 5 if (shift < 16) {
324 1 4 *dst->pos++ = shift? '=' : base64_alphabet[0x3F & (accum >> 6)];
329 444 82 while (src->pos < src->lim) {
331 0 444 if (cp < 0)
334 0 444 if (len < 0)
337 0 82 if (dst->pos != dst->lim) {
356 78 23 dst.encoding= encoding >= 0? encoding : src->encoding;
357 27 74 if (sv_isobject(dst_sv)) {
363 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)
366 74 0 if (SvTYPE(dst_sv) > SVt_PVMG || SvROK(dst_sv)) {
0 74 if (SvTYPE(dst_sv) > SVt_PVMG || SvROK(dst_sv)) {
372 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)) {
379 0 101 if (need_bytes < 0)
382 27 74 if (dst_sbuf) {
386 20 7 if (!append)
397 72 2 if (!append)
400 66 8 if (dst_wide) SvPVutf8(dst_sv, len);
403 2 72 sv_grow(dst_sv, (append? len : 0) + need_bytes + 1);
409 0 101 if (!secret_buffer_transcode(src, &dst)) {
410 0 0 if (!src->error) src->error= dst.error;
414 27 74 if (dst_sbuf) {
419 0 74 SvSETMAGIC(dst_sv);
438 339 45 if (val > 127) {
441 1662 339 while (tmp) {
450 0 384 ASSUME(enc_len < 127);
453 45 339 if (val <= 127) {
458 1662 339 while (tmp) {
474 0 384 if (pos >= lim) {
483 339 45 if ((result & 0x80)) {
486 0 339 if (n == 0) {
493 0 339 if (n > sizeof(UV)) {
498 0 339 if ((size_t)(lim - pos) < (size_t)n) {
508 0 339 if (!result) {
513 1323 339 while (pos < lim)
516 0 339 if (result < 0x80) {
521 384 0 if (out) *out = result;
540 1539 384 while (tmp) {
551 1539 384 if (tmp)
554 1539 384 } while (tmp);
555 0 384 ASSUME(pos == (U8*)(buf->data + buf->len));
566 0 384 if (pos >= lim) {
572 1539 384 while (*pos++ & 0x80) {
573 0 1539 if (pos >= lim) {
578 3 1536 if (shift > sizeof(UV)*8 - 7) {
580 3 0 if (shift >= sizeof(UV)*8 || (payload >> (sizeof(UV)*8 - shift))) {
0 3 if (shift >= sizeof(UV)*8 || (payload >> (sizeof(UV)*8 - shift))) {
589 3 381 if (!payload && result != 0) {
0 3 if (!payload && result != 0) {
593 384 0 if (out) *out = result;
612 1539 387 while (tmp) {
619 1926 387 for (shift= (enc_len-1) * 7; shift >= 0; shift -= 7) {
621 1539 387 if (shift)
625 0 387 ASSUME(pos == (U8*)(buf->data + buf->len));
635 0 395 if (pos >= lim) {
640 0 395 if (*pos == 0x80) {
645 1539 395 while (*pos++ & 0x80) {
647 0 1539 if (result >> (sizeof(UV)*8 - 7)) {
651 0 1539 if (pos >= lim) {
657 395 0 if (out) *out = result;
673 286 3 bool multi= 0 != (flags & SECRET_BUFFER_MATCH_MULTI) || cset->match_multi;
223 63 bool multi= 0 != (flags & SECRET_BUFFER_MATCH_MULTI) || cset->match_multi;
676 86 203 int step= reverse? -1 : 1;
677 86 203 U8 *pos= reverse? parse->lim-1 : parse->pos,
678 86 203 *lim= reverse? parse->pos-1 : parse->lim,
682 1097 5 while (pos != lim) {
683 238 859 if (sbc_bitmap_test(cset->bitmap, *pos) != negate) {
685 105 133 if (span_start)
688 27 106 if (!multi) {
693 784 75 } else if (anchored && !span_start)
152 632 } else if (anchored && !span_start)
700 0 289 if (consttime) {
702 0 0 while (pos != lim) {
709 86 203 if (reverse) {
711 21 65 parse->lim= span_start? span_start + 1 : parse->pos;
714 91 112 parse->pos= span_start? span_start : parse->lim;
727 9 0 bool multi= 0 != (flags & SECRET_BUFFER_MATCH_MULTI) || cset->match_multi;
2 7 bool multi= 0 != (flags & SECRET_BUFFER_MATCH_MULTI) || cset->match_multi;
732 5 4 U8 *span_mark= NULL, *prev_mark= reverse? parse->lim : parse->pos;
734 37 0 while (parse->pos < parse->lim) {
736 19 18 : sb_parse_next_codepoint(parse);
738 1 36 if (codepoint < 0) {// encoding error
742 10 26 if (sbc_test_codepoint(aTHX_ cset, codepoint) != negate) {
745 2 8 if (span_started)
750 6 2 if (!multi) {
751 4 2 prev_mark= reverse? parse->lim : parse->pos;
754 0 26 } else if (anchored && !span_started)
0 0 } else if (anchored && !span_started)
756 14 14 prev_mark= reverse? parse->lim : parse->pos;
761 0 9 if (consttime) {
763 0 0 while (parse->pos < parse->lim) {
765 0 0 : sb_parse_next_codepoint(parse);
767 0 0 if (codepoint < 0) { // encoding error
776 1 8 if (encoding_error)
779 8 0 if (span_started) { // and implicitly ends span
780 5 3 if (reverse) {
797 69 18 while (lhs->pos < lhs->lim && rhs->pos < rhs->lim) {
69 0 while (lhs->pos < lhs->lim && rhs->pos < rhs->lim) {
799 0 69 if (lhs_cp < 0)
802 0 69 if (rhs_cp < 0)
804 2 67 if (lhs_cp != rhs_cp && !ret)
2 0 if (lhs_cp != rhs_cp && !ret)
805 2 0 ret= lhs_cp < rhs_cp? -1 : 1;
808 16 2 : (lhs->pos < lhs->lim)? 1 /* right string shorter than left */
809 16 0 : (rhs->pos < rhs->lim)? -1 /* left string shorter than right */
810 0 16 : 0;
819 3368 1 if (encoding == SECRET_BUFFER_ENCODING_ASCII
820 577 2791 || encoding == SECRET_BUFFER_ENCODING_ISO8859_1
821 335 242 || encoding == SECRET_BUFFER_ENCODING_UTF8
823 0 3127 if (lim - pos < 1)
826 121 3006 if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_ASCII)
1 120 if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_ASCII)
828 120 3006 else if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_UTF8) {
47 73 else if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_UTF8) {
832 0 13 { if (lim - pos < 3) goto incomplete;
836 0 13 if ((*pos & 0xC0) != 0x80) goto invalid;
840 0 14 { if (lim - pos < 2) goto incomplete;
844 0 27 if ((*pos & 0xC0) != 0x80) goto invalid;
848 0 20 { if (lim - pos < 1) goto incomplete;
852 0 47 if ((*pos & 0xC0) != 0x80) goto invalid;
859 0 47 if (cp < min_cp)
861 0 47 else if (cp > 0x10FFFF)
866 221 21 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
867 15 206 || encoding == SECRET_BUFFER_ENCODING_UTF16BE
870 0 36 if (lim - pos < 2)
874 10 26 if (cp >= 0xD800 && cp <= 0xDFFF) {
10 0 if (cp >= 0xD800 && cp <= 0xDFFF) {
875 0 10 if (lim - pos < 2)
879 10 0 if (w2 < 0xDC00 || w2 > 0xDFFF)
0 10 if (w2 < 0xDC00 || w2 > 0xDFFF)
884 38 168 else if (encoding == SECRET_BUFFER_ENCODING_HEX) {
886 38 0 while (pos < lim && isspace(*pos))
0 38 while (pos < lim && isspace(*pos))
888 0 38 if (lim - pos < 2)
892 0 38 if (low >= ('a'-'0')) low -= ('a'-'0'-10);
893 8 30 else if (low >= ('A'-'0')) low -= ('A'-'0'-10);
894 0 38 if (high >= ('a'-'0')) high -= ('a'-'0'-10);
895 8 30 else if (high >= ('A'-'0')) high -= ('A'-'0'-10);
896 0 38 if ((low >> 4) | (high >> 4))
901 30 8 while (pos < lim && isspace(*pos))
0 30 while (pos < lim && isspace(*pos))
904 168 0 else if (encoding == SECRET_BUFFER_ENCODING_BASE64) {
906 168 0 while (pos < lim && *pos <= ' ')
0 168 while (pos < lim && *pos <= ' ')
909 168 0 if (pos < lim) {
910 0 168 if (base64_decode_table[*pos] < 0)
915 168 0 while (pos < lim && *pos <= ' ')
0 168 while (pos < lim && *pos <= ' ')
918 0 168 if (pos >= lim) {
922 0 168 if (base64_decode_table[*pos] < 0)
927 51 117 if (parse->pos_bit >= 6) {
931 47 8 while (pos < lim && *pos <= ' ')
4 43 while (pos < lim && *pos <= ' ')
937 117 0 while (next < lim && *next <= ' ')
0 117 while (next < lim && *next <= ' ')
939 117 0 if (next < lim && *next == '=') {
13 104 if (next < lim && *next == '=') {
945 0 0 else if (encoding == SECRET_BUFFER_ENCODING_I32) {
946 0 0 if (lim - pos < 4)
963 850 0 if (encoding == SECRET_BUFFER_ENCODING_ASCII
964 25 825 || encoding == SECRET_BUFFER_ENCODING_ISO8859_1
965 17 8 || encoding == SECRET_BUFFER_ENCODING_UTF8
967 0 842 if (lim <= pos)
971 4 838 if (cp >= 0x80 && encoding != SECRET_BUFFER_ENCODING_ISO8859_1) {
4 0 if (cp >= 0x80 && encoding != SECRET_BUFFER_ENCODING_ISO8859_1) {
973 0 4 if (encoding == SECRET_BUFFER_ENCODING_ASCII)
977 12 0 while (start >= pos && (*start & 0xC0) == 0x80)
8 4 while (start >= pos && (*start & 0xC0) == 0x80)
981 0 4 if (parse->pos != parse->lim) {// consumed all characters we gave it?
983 0 0 if (cp >= 0) // had a valid char, but extra 0x80 bytes
992 8 0 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
993 1 7 || encoding == SECRET_BUFFER_ENCODING_UTF16BE
995 0 1 if (lim - pos < 2)
1001 1 0 if (cp >= 0xD800 && cp <= 0xDFFF) {
1 0 if (cp >= 0xD800 && cp <= 0xDFFF) {
1002 0 1 if (lim - pos < 4)
1006 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)
1011 1 6 else if (encoding == SECRET_BUFFER_ENCODING_HEX) {
1013 1 0 while (pos < lim && isspace(lim[-1]))
0 1 while (pos < lim && isspace(lim[-1]))
1015 0 1 if (lim - pos < 2)
1016 0 0 SB_RETURN_ERROR((pos == lim? "end of span" : "incomplete hex pair at end of span"))
1019 1 0 if (low >= ('a'-'0')) low -= ('a'-'0'-10);
1020 0 0 else if (low >= ('A'-'0')) low -= ('A'-'0'-10);
1021 1 0 if (high >= ('a'-'0')) high -= ('a'-'0'-10);
1022 0 0 else if (high >= ('A'-'0')) high -= ('A'-'0'-10);
1023 0 1 if ((low >> 4) | (high >> 4))
1027 6 0 else if (encoding == SECRET_BUFFER_ENCODING_BASE64) {
1032 12 0 while (pos < lim && base64_decode_table[lim[-1]] < 0)
3 9 while (pos < lim && base64_decode_table[lim[-1]] < 0)
1034 9 0 if (pos < lim) {
1036 0 9 if (base64_decode_table[lim[-1]] < 0)
1042 3 6 if (lim[-1] == '=')
1046 9 0 while (pos < lim && base64_decode_table[lim[-1]] < 0)
0 9 while (pos < lim && base64_decode_table[lim[-1]] < 0)
1049 0 9 if (pos >= lim) {
1053 0 9 if (base64_decode_table[lim[-1]] < 0)
1058 3 6 if (parse->lim_bit >= 6) {
1063 0 3 while (pos < lim && base64_decode_table[lim[-1]] < 0)
0 0 while (pos < lim && base64_decode_table[lim[-1]] < 0)
1067 3 6 } while (again);
1069 0 0 else if (encoding == SECRET_BUFFER_ENCODING_I32) {
1070 0 0 if (lim - pos < 4)
1082 0 1202 if (encoding == SECRET_BUFFER_ENCODING_ASCII)
1083 0 0 return codepoint < 0x80? 1 : -1;
1084 110 1092 if (encoding == SECRET_BUFFER_ENCODING_ISO8859_1)
1085 110 0 return codepoint < 0x100? 1 : -1;
1086 736 356 else if (encoding == SECRET_BUFFER_ENCODING_UTF8)
1087 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;
1088 356 0 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
1089 0 356 || encoding == SECRET_BUFFER_ENCODING_UTF16BE)
1090 0 0 return codepoint >= 0xD800 && codepoint < 0xE000? -1
1091 0 0 : codepoint < 0x10000? 2 : 4;
0 0 : codepoint < 0x10000? 2 : 4;
1092 6 350 else if (encoding == SECRET_BUFFER_ENCODING_HEX)
1093 6 0 return codepoint < 0x100? 2 : -1;
1095 78 272 else if (encoding == SECRET_BUFFER_ENCODING_BASE64)
1096 78 0 return codepoint < 0x100? 1 : -1;
1097 272 0 else if (encoding == SECRET_BUFFER_ENCODING_I32)
1108 0 444 if (codepoint >= 0x110000)
1112 0 444 if (n < 0)
1114 0 444 if (dst->lim - dst_pos < n)
1118 444 0 if (encoding == SECRET_BUFFER_ENCODING_ASCII
1119 389 55 || encoding == SECRET_BUFFER_ENCODING_ISO8859_1
1120 368 21 || encoding == SECRET_BUFFER_ENCODING_UTF8
1139 21 0 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
1140 0 21 || encoding == SECRET_BUFFER_ENCODING_UTF16BE
1143 0 0 if (n == 2) {
1157 3 18 else if (encoding == SECRET_BUFFER_ENCODING_HEX) {
1161 18 0 else if (encoding == SECRET_BUFFER_ENCODING_I32) {