Branch Coverage

tar.c
Criterion Covered Total %
branch 368 554 66.4


line true false branch
43 0 5033 if (n == 0) return 0;
44 4 5029 if ((unsigned char)field[0] & 0x80) {
49 0 4 if ((unsigned char)field[0] & 0x40) return 0; /* negative */
51 28 4 for (i = 1; i < n; i++) {
59 37567 0 while (i < n && (field[i] == ' ' || field[i] == '0')) i++;
56 37511 while (i < n && (field[i] == ' ' || field[i] == '0')) i++;
32482 5029 while (i < n && (field[i] == ' ' || field[i] == '0')) i++;
61 13554 0 while (i < n && field[i] >= '0' && field[i] <= '7') {
8526 5028 while (i < n && field[i] >= '0' && field[i] <= '7') {
8525 1 while (i < n && field[i] >= '0' && field[i] <= '7') {
78 2023 1387 if (check == 0) digits = 1;
79 3588 3410 while (check) { digits++; check >>= 3; }
80 4 3406 if (digits > n - 1) fits_octal = 0;
82 3406 4 if (fits_octal) {
85 29346 3406 for (i = n - 1; i > 0; i--) {
92 32 4 for (i = n; i > 0; i--) {
108 787968 1539 for (i = 0; i < TAR_BLOCK_SIZE; i++) {
109 560196 227772 if (i >= offsetof(tar_header_t, chksum) &&
12312 547884 if (i >= offsetof(tar_header_t, chksum) &&
123 851 18432 for (i = 0; i < TAR_BLOCK_SIZE; i++) if (block[i]) return 0;
19283 36 for (i = 0; i < TAR_BLOCK_SIZE; i++) if (block[i]) return 0;
141 35 980 while (list) {
154 48 35 for (cur = *list; cur; cur = cur->next) {
155 0 48 if (strcmp(cur->key, key) == 0) {
177 0 0 while (list) {
178 0 0 if (strcmp(list->key, key) == 0) return list;
191 35 14 while (pos < len) {
194 101 0 while (pos < len && buf[pos] >= '0' && buf[pos] <= '9') {
66 35 while (pos < len && buf[pos] >= '0' && buf[pos] <= '9') {
66 0 while (pos < len && buf[pos] >= '0' && buf[pos] <= '9') {
198 35 0 if (pos == lstart || pos >= len || buf[pos] != ' ') return -1;
35 0 if (pos == lstart || pos >= len || buf[pos] != ' ') return -1;
0 35 if (pos == lstart || pos >= len || buf[pos] != ' ') return -1;
200 0 35 if (lstart + L > len) return -1;
203 35 0 if (rec_inner_end >= len || buf[rec_inner_end] != '\n') return -1;
0 35 if (rec_inner_end >= len || buf[rec_inner_end] != '\n') return -1;
205 0 35 if (!eq) return -1;
234 33 26 if (total == L) break;
255 20 4 if (c >= 'A' && c <= 'Z') return c - 'A';
14 6 if (c >= 'A' && c <= 'Z') return c - 'A';
256 6 4 if (c >= 'a' && c <= 'z') return c - 'a' + 26;
6 0 if (c >= 'a' && c <= 'z') return c - 'a' + 26;
257 4 0 if (c >= '0' && c <= '9') return c - '0' + 52;
4 0 if (c >= '0' && c <= '9') return c - '0' + 52;
258 0 0 if (c == '+') return 62;
259 0 0 if (c == '/') return 63;
270 0 2 if (!buf) return -1;
275 24 2 for (i = 0; i < in_len; i++) {
277 24 0 if (c == '=' || c == '\r' || c == '\n' || c == ' ' || c == '\t') {
24 0 if (c == '=' || c == '\r' || c == '\n' || c == ' ' || c == '\t') {
24 0 if (c == '=' || c == '\r' || c == '\n' || c == ' ' || c == '\t') {
24 0 if (c == '=' || c == '\r' || c == '\n' || c == ' ' || c == '\t') {
0 24 if (c == '=' || c == '\r' || c == '\n' || c == ' ' || c == '\t') {
278 0 0 if (c == '=') {
280 0 0 if (qi == 4) goto flush;
285 0 24 if (v < 0) { free(buf); return -1; }
287 6 18 if (qi == 4) {
289 6 0 if (quad[0] < 0 || quad[1] < 0) { free(buf); return -1; }
0 6 if (quad[0] < 0 || quad[1] < 0) { free(buf); return -1; }
291 6 0 if (quad[2] >= 0) {
293 6 0 if (quad[3] >= 0) {
311 0 2 if (!out) return NULL;
313 6 2 for (i = 0; i + 2 < in_len; i += 3) {
322 0 2 if (i < in_len) {
324 0 0 unsigned b = (i+1 < in_len) ? (unsigned char)in[i+1] : 0;
327 0 0 if (i + 1 < in_len) {
342 17 3 for (i = 0; i < value_len; i++) {
344 15 2 if (c == 0 || c == '\n' || c < 0x20 || c > 0x7e) return 1;
15 0 if (c == 0 || c == '\n' || c < 0x20 || c > 0x7e) return 1;
15 0 if (c == 0 || c == '\n' || c < 0x20 || c > 0x7e) return 1;
0 15 if (c == 0 || c == '\n' || c < 0x20 || c > 0x7e) return 1;
391 2890 2887 while (got < len) {
393 1 2889 if (n < 0) return -1;
394 1 2888 if (n == 0) return (int)got;
404 2081 2081 while (put < len) {
406 0 2081 if (n < 0) return -1;
407 0 2081 if (n == 0) return -1;
418 3 938 if (c->cur_xattrs) {
420 5 3 for (i = 0; i < c->cur_xattr_count; i++) {
442 0 69 if (!c) return -1;
454 0 872 while (c->entry_remaining > 0 || c->entry_pad > 0) {
0 872 while (c->entry_remaining > 0 || c->entry_pad > 0) {
455 0 0 if (c->entry_remaining > 0) {
458 0 0 if (n < (int)take) return -1;
461 0 0 if (c->entry_remaining == 0 && c->entry_pad > 0) {
0 0 if (c->entry_remaining == 0 && c->entry_pad > 0) {
464 0 0 if (n < (int)take) return -1;
478 1 888 if (n < 0) return -1;
479 0 888 if (n == 0) return 0; /* clean EOF */
480 1 887 if (n < TAR_BLOCK_SIZE) return -1;
481 36 851 if (tar_block_is_zero(buf)) {
493 1 850 if (stored != actual) return -1;
504 0 17 if (size == 0) {
506 0 0 return *out ? 0 : -1;
509 0 17 if (!buf) return -1;
511 0 17 if (n < (int)size) { free(buf); return -1; }
516 17 0 if (pad > 0) {
519 0 17 if (pn < (int)pad) { free(buf); return -1; }
531 39 16 while (list) {
535 5 34 if (strcmp(k, "path") == 0) {
542 0 34 } else if (strcmp(k, "linkpath") == 0) {
549 5 29 } else if (strcmp(k, "size") == 0) {
551 6 23 } else if (strcmp(k, "mtime") == 0) {
554 6 0 if (dot && (size_t)(dot - v) < vlen - 1) {
6 0 if (dot && (size_t)(dot - v) < vlen - 1) {
559 54 6 for (i = (size_t)(dot - v + 1); i < vlen && seen < 9; i++) {
54 0 for (i = (size_t)(dot - v + 1); i < vlen && seen < 9; i++) {
560 54 0 if (v[i] < '0' || v[i] > '9') break;
54 0 if (v[i] < '0' || v[i] > '9') break;
564 0 6 while (seen < 9) { ns *= 10; seen++; }
567 5 18 } else if (strcmp(k, "uid") == 0) {
569 5 13 } else if (strcmp(k, "gid") == 0) {
571 8 5 } else if (strncmp(k, "SCHILY.xattr.", 13) == 0
572 0 8 || strncmp(k, "LIBARCHIVE.xattr.", 17) == 0) {
573 5 0 size_t prefix_len = (k[0] == 'S') ? 13 : 17;
577 5 0 if (xname_len > 4 && strcmp(xname + xname_len - 4, ".b64") == 0) {
2 3 if (xname_len > 4 && strcmp(xname + xname_len - 4, ".b64") == 0) {
583 2 3 if (is_b64) {
584 0 2 if (b64_decode(v, vlen, &decoded, &dec_len) < 0) {
594 3 2 if (c->cur_xattr_count >= c->cur_xattr_cap) {
595 0 3 size_t ncap = c->cur_xattr_cap ? c->cur_xattr_cap * 2 : 4;
597 0 3 if (!na) { free(decoded); list = list->next; continue; }
609 0 8 } else if (strncmp(k, "GNU.sparse.", 11) == 0) {
611 0 0 if (!c->sparse_warning_emitted) {
646 0 872 if (consume_pending_padding(c) < 0) return -1;
659 3 886 if (rc < 0) { pax_kv_free(per_entry); free(long_name); free(long_link); return -1; }
660 36 850 if (rc == 0) {
668 847 3 if (tf == TF_GNU_LONGNAME || tf == TF_GNU_LONGLINK) {
0 847 if (tf == TF_GNU_LONGNAME || tf == TF_GNU_LONGLINK) {
670 0 3 if (read_payload(c, size, &payload) < 0) {
673 3 0 if (tf == TF_GNU_LONGNAME) { free(long_name); long_name = payload; }
677 12 835 if (tf == TF_PAX_FILE) {
679 0 12 if (read_payload(c, size, &payload) < 0) {
686 2 833 if (tf == TF_PAX_GLOBAL) {
688 0 2 if (read_payload(c, size, &payload) < 0) {
697 3 830 if (long_name) {
702 0 830 } else if (h.prefix[0]) {
721 0 833 if (long_link) {
726 6 827 } else if (h.linkname[0]) {
744 4 829 if (c->global_kv) apply_pax_to_entry(c, c->global_kv, out);
745 12 821 if (per_entry) apply_pax_to_entry(c, per_entry, out);
748 3 830 if (c->cur_xattr_count) {
754 820 13 c->entry_remaining = (out->type == AE_FILE) ? out->size : 0;
755 13 820 if (out->type != AE_FILE) {
761 820 13 : 0;
772 818 1127 if (c->entry_remaining == 0) return 0;
775 0 1127 if (n < (int)take) return -1;
779 809 318 if (c->entry_remaining == 0 && c->entry_pad > 0) {
803 6 if (c->entry_remaining == 0 && c->entry_pad > 0) {
782 0 803 if (pn < (int)c->entry_pad) return -1;
792 0 69 if (!cursor) return;
806 0 39 if (!opts) return FMT_AUTO;
808 10 29 if (!sv || !*sv || !SvOK(*sv)) return FMT_AUTO;
10 0 if (!sv || !*sv || !SvOK(*sv)) return FMT_AUTO;
0 10 if (!sv || !*sv || !SvOK(*sv)) return FMT_AUTO;
811 1 9 if (n == 4 && memcmp(p, "auto", 4) == 0) return FMT_AUTO;
1 0 if (n == 4 && memcmp(p, "auto", 4) == 0) return FMT_AUTO;
812 5 4 if (n == 3 && memcmp(p, "pax", 3) == 0) return FMT_PAX;
4 1 if (n == 3 && memcmp(p, "pax", 3) == 0) return FMT_PAX;
813 1 4 if (n == 3 && memcmp(p, "gnu", 3) == 0) return FMT_GNU;
1 0 if (n == 3 && memcmp(p, "gnu", 3) == 0) return FMT_GNU;
814 4 0 if (n == 5 && memcmp(p, "ustar", 5) == 0) return FMT_USTAR;
4 0 if (n == 5 && memcmp(p, "ustar", 5) == 0) return FMT_USTAR;
838 24836 2764 for (i = 0; i < field_n - 1; i++) {
839 0 24836 if (cap > (UINT64_MAX >> 3)) return 1;
854 0 679 if (size == 0) return 0;
856 4 675 if (!pad) return 0;
867 0 673 const char *name = override_name ? override_name : e->name;
868 673 0 size_t name_len = override_name ? strlen(override_name) : e->name_len;
872 4 669 if (e->link_target && e->link_target_len) {
4 0 if (e->link_target && e->link_target_len) {
874 0 4 if (llen > sizeof h->linkname) llen = sizeof h->linkname;
878 673 0 tar_emit_numeric(h->mode, sizeof h->mode, (uint64_t)(e->mode ? e->mode : 0644));
924 0 3 if (emit_block(c, (char *)&h) < 0) return -1;
926 0 3 if (write_full(c->push, c->sink, payload, payload_len) < 0) return -1;
927 0 3 if (emit_padding_for(c, payload_len) < 0) return -1;
940 10 2 const char *base = e ? e->name : "";
941 10 2 size_t base_len = e ? e->name_len : 0;
942 12 0 const char *slash = base ? (const char *)memchr(base, '/', base_len) : NULL;
944 12 0 if (base) {
947 3 810 for (p = base; p < base + base_len; p++) if (*p == '/') slash = p;
813 12 for (p = base; p < base + base_len; p++) if (*p == '/') slash = p;
949 3 9 if (slash) {
954 7 2 } else if (e) {
976 0 12 if (emit_block(c, (char *)&h) < 0) return -1;
977 0 12 if (write_full(c->push, c->sink, records, records_len) < 0) return -1;
978 0 12 if (emit_padding_for(c, records_len) < 0) return -1;
993 7 3 if (e->name_len > 100 || force_all) cap += 32 + 8 + e->name_len;
2 5 if (e->name_len > 100 || force_all) cap += 32 + 8 + e->name_len;
994 10 0 if (e->link_target_len > 100 || force_all) cap += 32 + 12 + e->link_target_len;
5 5 if (e->link_target_len > 100 || force_all) cap += 32 + 12 + e->link_target_len;
995 10 0 if (!ustar_numeric_fits(e->size, sizeof ((tar_header_t *)0)->size) || force_all) cap += 64;
5 5 if (!ustar_numeric_fits(e->size, sizeof ((tar_header_t *)0)->size) || force_all) cap += 64;
996 4 6 if (e->mtime_ns) cap += 64;
997 8 2 if (!ustar_numeric_fits(e->uid, sizeof ((tar_header_t *)0)->uid) || force_all) cap += 32;
3 5 if (!ustar_numeric_fits(e->uid, sizeof ((tar_header_t *)0)->uid) || force_all) cap += 32;
998 8 2 if (!ustar_numeric_fits(e->gid, sizeof ((tar_header_t *)0)->gid) || force_all) cap += 32;
3 5 if (!ustar_numeric_fits(e->gid, sizeof ((tar_header_t *)0)->gid) || force_all) cap += 32;
999 5 10 for (i = 0; i < e->xattr_count; i++) {
1002 10 0 if (cap < 4096) cap = 4096;
1004 0 10 if (!buf) return -1;
1008 7 3 if (e->name_len > 100 || force_all) {
2 5 if (e->name_len > 100 || force_all) {
1012 0 10 if ((e->link_target_len > 100 && e->link_target_len) || (force_all && e->link_target_len)) {
0 0 if ((e->link_target_len > 100 && e->link_target_len) || (force_all && e->link_target_len)) {
5 5 if ((e->link_target_len > 100 && e->link_target_len) || (force_all && e->link_target_len)) {
0 5 if ((e->link_target_len > 100 && e->link_target_len) || (force_all && e->link_target_len)) {
1015 10 0 if (!ustar_numeric_fits(e->size, sizeof ((tar_header_t *)0)->size) || force_all) {
5 5 if (!ustar_numeric_fits(e->size, sizeof ((tar_header_t *)0)->size) || force_all) {
1019 4 6 if (e->mtime_ns) {
1024 8 2 if (!ustar_numeric_fits(e->uid, sizeof ((tar_header_t *)0)->uid) || force_all) {
3 5 if (!ustar_numeric_fits(e->uid, sizeof ((tar_header_t *)0)->uid) || force_all) {
1028 8 2 if (!ustar_numeric_fits(e->gid, sizeof ((tar_header_t *)0)->gid) || force_all) {
3 5 if (!ustar_numeric_fits(e->gid, sizeof ((tar_header_t *)0)->gid) || force_all) {
1033 5 10 for (i = 0; i < e->xattr_count; i++) {
1037 2 3 snprintf(keybuf, sizeof keybuf, "SCHILY.xattr.%.*s%s",
1039 2 3 if (b64) {
1041 2 0 if (enc) {
1061 0 39 if (fmt < 0) return -1;
1063 0 39 if (!c) return -1;
1069 39 0 if (opts) {
1071 2 37 if (gm && *gm && SvROK(*gm) && SvTYPE(SvRV(*gm)) == SVt_PVHV) {
2 0 if (gm && *gm && SvROK(*gm) && SvTYPE(SvRV(*gm)) == SVt_PVHV) {
2 0 if (gm && *gm && SvROK(*gm) && SvTYPE(SvRV(*gm)) == SVt_PVHV) {
2 0 if (gm && *gm && SvROK(*gm) && SvTYPE(SvRV(*gm)) == SVt_PVHV) {
1077 4 2 while ((he = hv_iternext(gh))) {
1084 0 4 if (rpos + need > rcap) {
1085 0 0 while (rpos + need > rcap) rcap *= 2;
1094 2 0 if (rpos > 0) {
1095 0 2 if (emit_pax_header(c, TF_PAX_GLOBAL, NULL, records, rpos) < 0) {
1119 4 674 int needs_long_link = entry->link_target && !ustar_link_fits(entry);
0 4 int needs_long_link = entry->link_target && !ustar_link_fits(entry);
1121 678 0 if (!ustar_numeric_fits(entry->size, sizeof ((tar_header_t *)0)->size)
1122 674 4 || !ustar_numeric_fits(entry->uid, sizeof ((tar_header_t *)0)->uid)
1123 674 0 || !ustar_numeric_fits(entry->gid, sizeof ((tar_header_t *)0)->gid)
1124 674 0 || !ustar_numeric_fits(entry->mtime, sizeof ((tar_header_t *)0)->mtime)
1125 671 3 || entry->mtime_ns
1126 2 669 || entry->xattr_count) {
1130 4 674 if (c->format == FMT_USTAR) {
1131 3 1 if (needs_pax || needs_long_name || needs_long_link) return -1;
0 3 if (needs_pax || needs_long_name || needs_long_link) return -1;
0 0 if (needs_pax || needs_long_name || needs_long_link) return -1;
1132 2 672 } else if (c->format == FMT_GNU) {
1133 1 1 if (needs_pax) return -1;
1134 0 1 if (needs_long_name || needs_long_link) needs_gnu = 1;
0 0 if (needs_long_name || needs_long_link) needs_gnu = 1;
1135 5 667 } else if (c->format == FMT_PAX) {
1138 5 662 if (needs_pax) needs_pax = 1;
1139 660 2 else if (needs_long_name || needs_long_link) needs_gnu = 1;
0 660 else if (needs_long_name || needs_long_link) needs_gnu = 1;
1143 3 670 if (needs_gnu) {
1144 3 0 if (needs_long_name && entry->name_len) {
3 0 if (needs_long_name && entry->name_len) {
1145 0 3 if (emit_gnu_longlink(c, TF_GNU_LONGNAME, entry->name, entry->name_len + 1) < 0) return -1;
1147 0 3 if (needs_long_link && entry->link_target_len) {
0 0 if (needs_long_link && entry->link_target_len) {
1148 0 0 if (emit_gnu_longlink(c, TF_GNU_LONGLINK, entry->link_target, entry->link_target_len + 1) < 0) return -1;
1153 10 663 if (needs_pax) {
1156 0 10 if (build_pax_for_entry(entry, &records, &rlen, c->format == FMT_PAX) < 0) return -1;
1157 10 0 if (rlen > 0) {
1158 0 10 if (emit_pax_header(c, TF_PAX_FILE, entry, records, rlen) < 0) {
1182 6 667 if (entry->name_len > 100) {
1190 0 673 if (emit_block(c, (char *)&h) < 0) return -1;
1193 664 9 if (entry->size > 0 && content) {
664 0 if (entry->size > 0 && content) {
1194 0 664 if (write_full(c->push, c->sink, content, (size_t)entry->size) < 0) return -1;
1195 0 664 if (emit_padding_for(c, entry->size) < 0) return -1;
1196 0 9 } else if (len > 0 && content) {
0 0 } else if (len > 0 && content) {
1197 0 0 if (write_full(c->push, c->sink, content, len) < 0) return -1;
1198 0 0 if (emit_padding_for(c, len) < 0) return -1;
1208 0 39 if (!cursor) return 0;
1224 0 0 if (len < TAR_BLOCK_SIZE) return 0;
1226 0 0 if (memcmp(h->magic, "ustar", 5) == 0) {
1230 0 0 if (stored == actual) return 90;
1236 0 0 if (stored == actual && stored != 0) return 50;
0 0 if (stored == actual && stored != 0) return 50;