Branch Coverage

secret_buffer_parse.c
Criterion Covered Total %
branch 392 594 65.9


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) {
300 0 24 if (dst->pos + 4 > dst->lim) {
318 5 5 if (dst->pos + (shift < 16? 4 : 0) != dst->lim) {
0 10 if (dst->pos + (shift < 16? 4 : 0) != dst->lim) {
323 5 5 if (shift < 16) {
325 0 5 if (dst->pos + 4 > dst->lim) {
332 1 4 writable[2] = shift? '=' : base64_alphabet[0x3F & (accum >> 6)];
337 444 82 while (src->pos < src->lim) {
339 0 444 if (cp < 0)
342 0 444 if (len < 0)
345 0 82 if (dst->pos != dst->lim) {
364 78 23 dst.encoding= encoding >= 0? encoding : src->encoding;
365 27 74 if (sv_isobject(dst_sv)) {
371 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)
374 74 0 if (SvTYPE(dst_sv) > SVt_PVMG || SvROK(dst_sv)) {
0 74 if (SvTYPE(dst_sv) > SVt_PVMG || SvROK(dst_sv)) {
380 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)) {
387 0 101 if (need_bytes < 0)
390 27 74 if (dst_sbuf) {
394 20 7 if (!append)
406 72 2 if (!append)
409 66 8 if (dst_wide) SvPVutf8(dst_sv, len);
412 2 72 sv_grow(dst_sv, (append? len : 0) + need_bytes + 1);
419 0 101 if (!secret_buffer_transcode(src, &dst)) {
420 0 0 if (!src->error) src->error= dst.error;
424 27 74 if (dst_sbuf) {
429 0 74 SvSETMAGIC(dst_sv);
448 339 45 if (val > 127) {
451 1662 339 while (tmp) {
460 0 384 ASSUME(enc_len < 127);
463 45 339 if (val <= 127) {
468 1662 339 while (tmp) {
484 0 384 if (pos >= lim) {
493 339 45 if ((result & 0x80)) {
496 0 339 if (n == 0) {
503 0 339 if (n > sizeof(UV)) {
508 0 339 if ((size_t)(lim - pos) < (size_t)n) {
518 0 339 if (!result) {
523 1323 339 while (pos < lim)
526 0 339 if (result < 0x80) {
531 384 0 if (out) *out = result;
550 1539 384 while (tmp) {
561 1539 384 if (tmp)
564 1539 384 } while (tmp);
565 0 384 ASSUME(pos == (U8*)(buf->data + buf->len));
576 0 384 if (pos >= lim) {
582 1539 384 while (*pos++ & 0x80) {
583 0 1539 if (pos >= lim) {
588 3 1536 if (shift > sizeof(UV)*8 - 7) {
590 3 0 if (shift >= sizeof(UV)*8 || (payload >> (sizeof(UV)*8 - shift))) {
0 3 if (shift >= sizeof(UV)*8 || (payload >> (sizeof(UV)*8 - shift))) {
599 3 381 if (!payload && result != 0) {
0 3 if (!payload && result != 0) {
603 384 0 if (out) *out = result;
622 1539 387 while (tmp) {
629 1926 387 for (shift= (enc_len-1) * 7; shift >= 0; shift -= 7) {
631 1539 387 if (shift)
635 0 387 ASSUME(pos == (U8*)(buf->data + buf->len));
645 0 395 if (pos >= lim) {
650 0 395 if (*pos == 0x80) {
655 1539 395 while (*pos++ & 0x80) {
657 0 1539 if (result >> (sizeof(UV)*8 - 7)) {
661 0 1539 if (pos >= lim) {
667 395 0 if (out) *out = result;
683 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;
686 86 203 int step= reverse? -1 : 1;
687 86 203 const U8 *pos= reverse? parse->lim-1 : parse->pos,
688 86 203 *lim= reverse? parse->pos-1 : parse->lim,
692 1097 5 while (pos != lim) {
693 238 859 if (sbc_bitmap_test(cset->bitmap, *pos) != negate) {
695 105 133 if (span_start)
698 27 106 if (!multi) {
703 784 75 } else if (anchored && !span_start)
152 632 } else if (anchored && !span_start)
710 0 289 if (consttime) {
712 0 0 while (pos != lim) {
719 86 203 if (reverse) {
721 21 65 parse->lim= span_start? span_start + 1 : parse->pos;
724 91 112 parse->pos= span_start? span_start : parse->lim;
737 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;
742 5 4 const U8 *span_mark= NULL, *prev_mark= reverse? parse->lim : parse->pos;
744 37 0 while (parse->pos < parse->lim) {
746 19 18 : sb_parse_next_codepoint(parse);
748 1 36 if (codepoint < 0) {// encoding error
752 10 26 if (sbc_test_codepoint(aTHX_ cset, codepoint) != negate) {
755 2 8 if (span_started)
760 6 2 if (!multi) {
761 4 2 prev_mark= reverse? parse->lim : parse->pos;
764 0 26 } else if (anchored && !span_started)
0 0 } else if (anchored && !span_started)
766 14 14 prev_mark= reverse? parse->lim : parse->pos;
771 0 9 if (consttime) {
773 0 0 while (parse->pos < parse->lim) {
775 0 0 : sb_parse_next_codepoint(parse);
777 0 0 if (codepoint < 0) { // encoding error
786 1 8 if (encoding_error)
789 8 0 if (span_started) { // and implicitly ends span
790 5 3 if (reverse) {
807 69 18 while (lhs->pos < lhs->lim && rhs->pos < rhs->lim) {
69 0 while (lhs->pos < lhs->lim && rhs->pos < rhs->lim) {
809 0 69 if (lhs_cp < 0)
812 0 69 if (rhs_cp < 0)
814 2 67 if (lhs_cp != rhs_cp && !ret)
2 0 if (lhs_cp != rhs_cp && !ret)
815 2 0 ret= lhs_cp < rhs_cp? -1 : 1;
818 16 2 : (lhs->pos < lhs->lim)? 1 /* right string shorter than left */
819 16 0 : (rhs->pos < rhs->lim)? -1 /* left string shorter than right */
820 0 16 : 0;
829 3364 1 if (encoding == SECRET_BUFFER_ENCODING_ASCII
830 577 2787 || encoding == SECRET_BUFFER_ENCODING_ISO8859_1
831 335 242 || encoding == SECRET_BUFFER_ENCODING_UTF8
833 0 3123 if (lim - pos < 1)
836 116 3007 if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_ASCII)
1 115 if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_ASCII)
838 115 3007 else if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_UTF8) {
47 68 else if (cp >= 0x80 && encoding == SECRET_BUFFER_ENCODING_UTF8) {
842 0 13 { if (lim - pos < 3) goto incomplete;
846 0 13 if ((*pos & 0xC0) != 0x80) goto invalid;
850 0 14 { if (lim - pos < 2) goto incomplete;
854 0 27 if ((*pos & 0xC0) != 0x80) goto invalid;
858 0 20 { if (lim - pos < 1) goto incomplete;
862 0 47 if ((*pos & 0xC0) != 0x80) goto invalid;
869 0 47 if (cp < min_cp)
871 0 47 else if (cp > 0x10FFFF)
876 221 21 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
877 15 206 || encoding == SECRET_BUFFER_ENCODING_UTF16BE
880 0 36 if (lim - pos < 2)
884 10 26 if (cp >= 0xD800 && cp <= 0xDFFF) {
10 0 if (cp >= 0xD800 && cp <= 0xDFFF) {
885 0 10 if (lim - pos < 2)
889 10 0 if (w2 < 0xDC00 || w2 > 0xDFFF)
0 10 if (w2 < 0xDC00 || w2 > 0xDFFF)
894 38 168 else if (encoding == SECRET_BUFFER_ENCODING_HEX) {
896 38 0 while (pos < lim && isspace(*pos))
0 38 while (pos < lim && isspace(*pos))
898 0 38 if (lim - pos < 2)
902 0 38 if (low >= ('a'-'0')) low -= ('a'-'0'-10);
903 8 30 else if (low >= ('A'-'0')) low -= ('A'-'0'-10);
904 0 38 if (high >= ('a'-'0')) high -= ('a'-'0'-10);
905 8 30 else if (high >= ('A'-'0')) high -= ('A'-'0'-10);
906 0 38 if ((low >> 4) | (high >> 4))
911 30 8 while (pos < lim && isspace(*pos))
0 30 while (pos < lim && isspace(*pos))
914 168 0 else if (encoding == SECRET_BUFFER_ENCODING_BASE64) {
916 168 0 while (pos < lim && *pos <= ' ')
0 168 while (pos < lim && *pos <= ' ')
919 168 0 if (pos < lim) {
920 0 168 if (base64_decode_table[*pos] < 0)
925 168 0 while (pos < lim && *pos <= ' ')
0 168 while (pos < lim && *pos <= ' ')
928 0 168 if (pos >= lim) {
932 0 168 if (base64_decode_table[*pos] < 0)
937 51 117 if (parse->pos_bit >= 6) {
941 47 8 while (pos < lim && *pos <= ' ')
4 43 while (pos < lim && *pos <= ' ')
947 117 0 while (next < lim && *next <= ' ')
0 117 while (next < lim && *next <= ' ')
949 117 0 if (next < lim && *next == '=') {
13 104 if (next < lim && *next == '=') {
955 0 0 else if (encoding == SECRET_BUFFER_ENCODING_I32) {
956 0 0 if (lim - pos < 4)
973 850 0 if (encoding == SECRET_BUFFER_ENCODING_ASCII
974 25 825 || encoding == SECRET_BUFFER_ENCODING_ISO8859_1
975 17 8 || encoding == SECRET_BUFFER_ENCODING_UTF8
977 0 842 if (lim <= pos)
981 4 838 if (cp >= 0x80 && encoding != SECRET_BUFFER_ENCODING_ISO8859_1) {
4 0 if (cp >= 0x80 && encoding != SECRET_BUFFER_ENCODING_ISO8859_1) {
983 0 4 if (encoding == SECRET_BUFFER_ENCODING_ASCII)
987 12 0 while (start >= pos && (*start & 0xC0) == 0x80)
8 4 while (start >= pos && (*start & 0xC0) == 0x80)
991 0 4 if (parse->pos != parse->lim) {// consumed all characters we gave it?
993 0 0 if (cp >= 0) // had a valid char, but extra 0x80 bytes
1002 8 0 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
1003 1 7 || encoding == SECRET_BUFFER_ENCODING_UTF16BE
1005 0 1 if (lim - pos < 2)
1011 1 0 if (cp >= 0xD800 && cp <= 0xDFFF) {
1 0 if (cp >= 0xD800 && cp <= 0xDFFF) {
1012 0 1 if (lim - pos < 4)
1016 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)
1021 1 6 else if (encoding == SECRET_BUFFER_ENCODING_HEX) {
1023 1 0 while (pos < lim && isspace(lim[-1]))
0 1 while (pos < lim && isspace(lim[-1]))
1025 0 1 if (lim - pos < 2)
1026 0 0 SB_RETURN_ERROR((pos == lim? "end of span" : "incomplete hex pair at end of span"))
1029 1 0 if (low >= ('a'-'0')) low -= ('a'-'0'-10);
1030 0 0 else if (low >= ('A'-'0')) low -= ('A'-'0'-10);
1031 1 0 if (high >= ('a'-'0')) high -= ('a'-'0'-10);
1032 0 0 else if (high >= ('A'-'0')) high -= ('A'-'0'-10);
1033 0 1 if ((low >> 4) | (high >> 4))
1037 6 0 else if (encoding == SECRET_BUFFER_ENCODING_BASE64) {
1042 12 0 while (pos < lim && base64_decode_table[lim[-1]] < 0)
3 9 while (pos < lim && base64_decode_table[lim[-1]] < 0)
1044 9 0 if (pos < lim) {
1046 0 9 if (base64_decode_table[lim[-1]] < 0)
1052 3 6 if (lim[-1] == '=')
1056 9 0 while (pos < lim && base64_decode_table[lim[-1]] < 0)
0 9 while (pos < lim && base64_decode_table[lim[-1]] < 0)
1059 0 9 if (pos >= lim) {
1063 0 9 if (base64_decode_table[lim[-1]] < 0)
1068 3 6 if (parse->lim_bit >= 6) {
1073 0 3 while (pos < lim && base64_decode_table[lim[-1]] < 0)
0 0 while (pos < lim && base64_decode_table[lim[-1]] < 0)
1077 3 6 } while (again);
1079 0 0 else if (encoding == SECRET_BUFFER_ENCODING_I32) {
1080 0 0 if (lim - pos < 4)
1092 0 1202 if (encoding == SECRET_BUFFER_ENCODING_ASCII)
1093 0 0 return codepoint < 0x80? 1 : -1;
1094 110 1092 if (encoding == SECRET_BUFFER_ENCODING_ISO8859_1)
1095 110 0 return codepoint < 0x100? 1 : -1;
1096 736 356 else if (encoding == SECRET_BUFFER_ENCODING_UTF8)
1097 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;
1098 356 0 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
1099 0 356 || encoding == SECRET_BUFFER_ENCODING_UTF16BE)
1100 0 0 return codepoint >= 0xD800 && codepoint < 0xE000? -1
1101 0 0 : codepoint < 0x10000? 2 : 4;
0 0 : codepoint < 0x10000? 2 : 4;
1102 6 350 else if (encoding == SECRET_BUFFER_ENCODING_HEX)
1103 6 0 return codepoint < 0x100? 2 : -1;
1105 78 272 else if (encoding == SECRET_BUFFER_ENCODING_BASE64)
1106 78 0 return codepoint < 0x100? 1 : -1;
1107 272 0 else if (encoding == SECRET_BUFFER_ENCODING_I32)
1118 0 444 if (codepoint >= 0x110000)
1122 0 444 if (n < 0)
1124 0 444 if (dst->lim - dst_pos < n)
1128 444 0 if (encoding == SECRET_BUFFER_ENCODING_ASCII
1129 389 55 || encoding == SECRET_BUFFER_ENCODING_ISO8859_1
1130 368 21 || encoding == SECRET_BUFFER_ENCODING_UTF8
1149 21 0 else if (encoding == SECRET_BUFFER_ENCODING_UTF16LE
1150 0 21 || encoding == SECRET_BUFFER_ENCODING_UTF16BE
1153 0 0 if (n == 2) {
1167 3 18 else if (encoding == SECRET_BUFFER_ENCODING_HEX) {
1171 18 0 else if (encoding == SECRET_BUFFER_ENCODING_I32) {