Branch Coverage

deps/libgit2/src/util/fs_path.c
Criterion Covered Total %
branch 235 632 37.1


line true false branch
40 9889 0 if (!(0x80 & (unsigned char)*path))
41 9710 179 return *path && path[1] == ':' ? 2 : 0;
0 9710 return *path && path[1] == ':' ? 2 : 0;
51 0 0 for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++)
0 0 for (i = 1; i < 4 && (0x80 & (unsigned char)path[i]); i++)
53 0 0 return path[i] == ':' ? i + 1 : 0;
110 0 0 if (path == NULL || *path == '\0') {
0 0 if (path == NULL || *path == '\0') {
118 0 0 while (endp > path && *endp == '/')
0 0 while (endp > path && *endp == '/')
122 0 0 if (endp == path && *endp == '/') {
0 0 if (endp == path && *endp == '/') {
130 0 0 while (startp > path && *(startp - 1) != '/')
0 0 while (startp > path && *(startp - 1) != '/')
139 0 0 if (buffer != NULL && git_str_set(buffer, startp, len) < 0)
0 0 if (buffer != NULL && git_str_set(buffer, startp, len) < 0)
183 1407 0 if (path == NULL || *path == '\0') {
0 1407 if (path == NULL || *path == '\0') {
191 1468 0 while (endp > path && *endp == '/')
61 1407 while (endp > path && *endp == '/')
194 0 1407 if (endp - path + 1 > INT_MAX) {
199 0 1407 if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
205 16623 182 while (endp > path && *endp != '/')
15398 1225 while (endp > path && *endp != '/')
209 182 1225 if (endp == path) {
210 0 182 path = (*endp == '/') ? "/" : ".";
217 1225 0 } while (endp > path && *endp == '/');
0 1225 } while (endp > path && *endp == '/');
219 0 1225 if (endp - path + 1 > INT_MAX) {
224 0 1225 if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
233 1407 0 if (buffer) {
234 0 1407 if (git_str_set(buffer, path, len) < 0)
236 0 1407 if (is_prefix && git_str_putc(buffer, '/') < 0)
0 0 if (is_prefix && git_str_putc(buffer, '/') < 0)
272 0 0 if (!buffer || buffer->size <= 0)
0 0 if (!buffer || buffer->size <= 0)
277 0 0 if (slash >= 0 && buffer->ptr[slash] == '/')
0 0 if (slash >= 0 && buffer->ptr[slash] == '/')
288 0 9889 if ((prefix_len = dos_drive_prefix_length(path)))
307 1558 8331 if (path[offset] == '/')
317 0 448 if (ceiling < 0)
320 896 0 while (path->size > (size_t)ceiling) {
321 448 448 if (path->ptr[path->size-1] != '/')
334 0 1793 GIT_ASSERT_ARG(path_out);
335 0 1793 GIT_ASSERT_ARG(path);
339 1782 11 if (base != NULL && root < 0) {
1731 51 if (base != NULL && root < 0) {
340 0 1731 if (git_str_joinpath(path_out, base, path) < 0)
345 0 62 if (git_str_sets(path_out, path) < 0)
348 0 62 if (root < 0)
350 51 11 else if (base)
354 1629 164 if (root_at)
364 0 19 if (path->size == 0)
367 268 19 for (p = path->ptr, q = path->ptr; *q; p++, q++) {
370 27 241 while (*q == '/' && *(q+1) == '/') {
0 27 while (*q == '/' && *(q+1) == '/') {
383 0 94 GIT_ASSERT_ARG(path_out);
384 0 94 GIT_ASSERT_ARG(path);
387 5 89 if (base != NULL && git_fs_path_root(path) < 0) {
0 5 if (base != NULL && git_fs_path_root(path) < 0) {
388 0 0 if (git_str_joinpath(path_out, base, path) < 0)
393 0 94 if (p_realpath(path, buf) == NULL) {
395 0 0 int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
0 0 int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
409 30 0 return (error < 0) ? error : git_fs_path_to_dir(path_out);
415 2709 1668 git_str_len(path) > 0 &&
419 0 4559 return git_str_oom(path) ? -1 : 0;
426 0 0 if (end && path[end - 1] != '/' && end < size) {
0 0 if (end && path[end - 1] != '/' && end < size) {
0 0 if (end && path[end - 1] != '/' && end < size) {
436 0 3 GIT_ASSERT_ARG(decoded_out);
437 0 3 GIT_ASSERT_ARG(input);
442 150 3 for(i = 0; i < len; i++)
446 150 0 if (c != '%')
449 0 0 if (i >= len - 2)
455 0 0 if (hi < 0 || lo < 0)
0 0 if (hi < 0 || lo < 0)
462 0 150 if (git_str_putc(decoded_out, c) < 0)
479 6 3 if (git__prefixcmp(file_url, "file://") == 0) {
480 6 0 if (file_url[7] == '/')
482 0 0 else if (git__prefixcmp(file_url + 7, "localhost/") == 0)
498 0 3 GIT_ASSERT_ARG(local_path_out);
499 0 3 GIT_ASSERT_ARG(file_url);
501 3 0 if ((offset = local_file_url_prefixlen(file_url)) < 0 ||
3 0 if ((offset = local_file_url_prefixlen(file_url)) < 0 ||
502 0 3 file_url[offset] == '\0' || file_url[offset] == '/')
524 0 839 GIT_ASSERT_ARG(path);
525 0 839 GIT_ASSERT_ARG(cb);
527 839 0 if (ceiling != NULL) {
528 839 0 if (git__prefixcmp(path->ptr, ceiling) == 0)
536 0 839 if (!scan) {
538 0 0 if (error)
539 0 0 ensure_error_set(error);
0 0 ensure_error_set(error);
0 0 ensure_error_set(error);
547 993 813 while (scan >= stop) {
551 26 967 if (error) {
552 13 13 ensure_error_set(error);
0 13 ensure_error_set(error);
0 13 ensure_error_set(error);
557 967 0 if (scan >= 0) {
565 839 0 if (scan >= 0)
569 813 26 if (!error && stop == 0 && iter.ptr[0] != '/') {
0 813 if (!error && stop == 0 && iter.ptr[0] != '/') {
0 0 if (!error && stop == 0 && iter.ptr[0] != '/') {
571 0 0 if (error)
572 0 0 ensure_error_set(error);
0 0 ensure_error_set(error);
0 0 ensure_error_set(error);
580 0 3137 GIT_ASSERT_ARG_WITH_RETVAL(path, false);
587 338 1694 if (p_stat(path, &st) < 0)
597 0 690 GIT_ASSERT_ARG_WITH_RETVAL(path, false);
598 473 217 if (p_stat(path, &st) < 0)
608 0 0 GIT_ASSERT_ARG_WITH_RETVAL(path, false);
609 0 0 if (p_lstat(path, &st) < 0)
671 0 2 if (!git_fs_path_isdir(path))
674 0 2 if ((error = git_str_sets(&dir, path)) != 0)
715 1208 0 if (p_lstat(path, st) == 0)
732 0 588 if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) ||
0 588 if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) ||
733 0 588 GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) ||
738 0 588 if (git_str_joinpath(dir, dir->ptr, sub) < 0)
768 613 18 if (p_realpath(dir->ptr, buf) != NULL)
772 631 0 if (!error) /* && git_fs_path_isdir(dir->ptr) == false) */
773 0 631 error = (git_fs_path_dirname_r(dir, dir->ptr) < 0) ? -1 : 0;
775 631 0 if (!error)
786 182 0 GIT_ERROR_CHECK_ALLOC_STR(path);
0 182 GIT_ERROR_CHECK_ALLOC_STR(path);
788 0 182 if (ceiling > path->size)
792 182 0 if (ceiling == 0)
796 182 0 if (ceiling == 0) {
797 182 0 for (next = path->ptr; *next && git__isalpha(*next); ++next);
0 182 for (next = path->ptr; *next && git__isalpha(*next); ++next);
798 0 182 if (next[0] == ':' && next[1] == '/' && next[2] == '/')
0 0 if (next[0] == ':' && next[1] == '/' && next[2] == '/')
0 0 if (next[0] == ':' && next[1] == '/' && next[2] == '/')
804 182 182 while (*from) {
805 182 182 for (next = from; *next && *next != '/'; ++next);
182 0 for (next = from; *next && *next != '/'; ++next);
809 182 0 if (len == 1 && from[0] == '.')
182 0 if (len == 1 && from[0] == '.')
812 0 0 else if (len == 2 && from[0] == '.' && from[1] == '.') {
0 0 else if (len == 2 && from[0] == '.' && from[1] == '.') {
0 0 else if (len == 2 && from[0] == '.' && from[1] == '.') {
814 0 0 if (to == base && ceiling != 0) {
0 0 if (to == base && ceiling != 0) {
822 0 0 if (to == base) {
823 0 0 if (*next == '/')
826 0 0 if (to != from)
835 0 0 while (to > base && to[-1] == '/') to--;
0 0 while (to > base && to[-1] == '/') to--;
836 0 0 while (to > base && to[-1] != '/') to--;
0 0 while (to > base && to[-1] != '/') to--;
839 0 0 if (*next == '/' && *from != '/')
0 0 if (*next == '/' && *from != '/')
842 0 0 if (to != from)
850 0 182 while (*from == '/') from++;
876 137 83 if (cmp)
882 34 49 if (c1 == '\0' && isdir1)
1 33 if (c1 == '\0' && isdir1)
885 49 34 if (c2 == '\0' && isdir2)
2 47 if (c2 == '\0' && isdir2)
888 48 35 return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
895 166 8 for (p = one, q = two; *p && *q; p++, q++) {
166 0 for (p = one, q = two; *p && *q; p++, q++) {
896 28 138 if (*p == '/' && *q == '/')
28 0 if (*p == '/' && *q == '/')
898 14 124 else if (*p != *q)
902 21 1 return dirsep ? (dirsep - one) + 1 : 0;
910 0 0 for (p_dirsep = p = path->ptr, q_dirsep = q = parent; *p && *q; p++, q++) {
0 0 for (p_dirsep = p = path->ptr, q_dirsep = q = parent; *p && *q; p++, q++) {
911 0 0 if (*p == '/' && *q == '/') {
0 0 if (*p == '/' && *q == '/') {
915 0 0 else if (*p != *q)
920 0 0 if ((p_dirsep == path->ptr || q_dirsep == parent) &&
0 0 if ((p_dirsep == path->ptr || q_dirsep == parent) &&
0 0 if ((p_dirsep == path->ptr || q_dirsep == parent) &&
921 0 0 (*p_dirsep != '/' || *q_dirsep != '/')) {
927 0 0 if (*p == '/' && !*q)
0 0 if (*p == '/' && !*q)
929 0 0 else if (!*p && *q == '/')
0 0 else if (!*p && *q == '/')
931 0 0 else if (!*p && !*q)
0 0 else if (!*p && !*q)
940 0 0 if (!*q)
943 0 0 for (; (q = strchr(q, '/')) && *(q + 1); q++)
0 0 for (; (q = strchr(q, '/')) && *(q + 1); q++)
946 0 0 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3);
0 0 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3);
947 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen);
949 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1);
953 0 0 if (git_str_try_grow(path, alloclen, 1) < 0)
959 0 0 for (i = 0; i < depth; i++)
970 0 0 for (end = scan + pathlen; scan < end; ++scan)
971 0 0 if (*scan & 0x80)
1135 0 336 if (git_fs_path_to_dir(path) < 0)
1140 0 336 if ((dir = opendir(path->ptr)) == NULL) {
1142 0 0 if (errno == ENOENT)
1153 941 334 while ((de = readdir(dir)) != NULL) {
1157 668 273 if (git_fs_path_is_dot_or_dotdot(de_path))
1165 0 273 if ((error = git_str_put(path, de_path, de_len)) < 0)
1174 2 271 if (error != 0) {
1175 2 0 if (!git_error_last())
1176 0 2 ensure_error_set(error);
0 0 ensure_error_set(error);
0 2 ensure_error_set(error);
1366 0 448 GIT_ASSERT_ARG(diriter);
1367 0 448 GIT_ASSERT_ARG(path);
1371 0 448 if (git_str_puts(&diriter->path, path) < 0)
1376 0 448 if (diriter->path.size == 0) {
1381 2 446 if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
1407 0 1661 GIT_ASSERT_ARG(diriter);
1412 446 2107 if ((de = readdir(diriter->dir)) == NULL) {
1413 446 0 if (!errno)
1420 2107 0 } while (skip_dot && git_fs_path_is_dot_or_dotdot(de->d_name));
892 1215 } while (skip_dot && git_fs_path_is_dot_or_dotdot(de->d_name));
1433 1215 0 if (diriter->parent_len > 0 &&
1215 0 if (diriter->parent_len > 0 &&
1439 0 1215 if (git_str_oom(&diriter->path))
1450 0 0 GIT_ASSERT_ARG(out);
1451 0 0 GIT_ASSERT_ARG(out_len);
1452 0 0 GIT_ASSERT_ARG(diriter);
1453 0 0 GIT_ASSERT(diriter->path.size > diriter->parent_len);
1465 0 1215 GIT_ASSERT_ARG(out);
1466 0 1215 GIT_ASSERT_ARG(out_len);
1467 0 1215 GIT_ASSERT_ARG(diriter);
1476 0 1092 GIT_ASSERT_ARG(out);
1477 0 1092 GIT_ASSERT_ARG(diriter);
1484 0 448 if (diriter == NULL)
1487 446 2 if (diriter->dir) {
1513 0 2 GIT_ASSERT_ARG(contents);
1514 0 2 GIT_ASSERT_ARG(path);
1516 0 2 if ((error = git_fs_path_diriter_init(&iter, path, flags)) < 0)
1519 4 2 while ((error = git_fs_path_diriter_next(&iter)) == 0) {
1520 0 4 if ((error = git_fs_path_diriter_fullpath(&name, &name_len, &iter)) < 0)
1523 0 4 GIT_ASSERT(name_len > prefix_len);
1526 0 4 GIT_ERROR_CHECK_ALLOC(dup);
1528 0 4 if ((error = git_vector_insert(contents, dup)) < 0)
1532 2 0 if (error == GIT_ITEROVER)
1541 3 3 if (git_fs_path_is_local_file_url(url_or_path))
1556 0 0 size_t last = trailing_num ? 4 : 3;
1558 0 0 if (len < last || git__strncasecmp(component, dospath, 3) != 0)
0 0 if (len < last || git__strncasecmp(component, dospath, 3) != 0)
1561 0 0 if (trailing_num && (component[3] < '1' || component[3] > '9'))
0 0 if (trailing_num && (component[3] < '1' || component[3] > '9'))
0 0 if (trailing_num && (component[3] < '1' || component[3] > '9'))
1564 0 0 return (len > last &&
1565 0 0 component[last] != '.' &&
0 0 component[last] != '.' &&
1571 0 4887 if ((flags & GIT_FS_PATH_REJECT_BACKSLASH) && c == '\\')
0 0 if ((flags & GIT_FS_PATH_REJECT_BACKSLASH) && c == '\\')
1574 1170 3717 if ((flags & GIT_FS_PATH_REJECT_SLASH) && c == '/')
1 1169 if ((flags & GIT_FS_PATH_REJECT_SLASH) && c == '/')
1577 0 4886 if (flags & GIT_FS_PATH_REJECT_NT_CHARS) {
1578 0 0 if (c < 32)
1581 0 0 switch (c) {
1610 0 803 if (len == 0)
1613 803 0 if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) &&
7 796 if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) &&
1614 0 7 len == 1 && component[0] == '.')
1617 803 0 if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) &&
0 803 if ((flags & GIT_FS_PATH_REJECT_TRAVERSAL) &&
1618 0 0 len == 2 && component[0] == '.' && component[1] == '.')
0 0 len == 2 && component[0] == '.' && component[1] == '.')
1621 0 803 if ((flags & GIT_FS_PATH_REJECT_TRAILING_DOT) &&
0 0 if ((flags & GIT_FS_PATH_REJECT_TRAILING_DOT) &&
1625 0 803 if ((flags & GIT_FS_PATH_REJECT_TRAILING_SPACE) &&
0 0 if ((flags & GIT_FS_PATH_REJECT_TRAILING_SPACE) &&
1629 0 803 if ((flags & GIT_FS_PATH_REJECT_TRAILING_COLON) &&
0 0 if ((flags & GIT_FS_PATH_REJECT_TRAILING_COLON) &&
1633 0 803 if (flags & GIT_FS_PATH_REJECT_DOS_PATHS) {
1635 0 0 !validate_dospath(component, len, "PRN", false) ||
1636 0 0 !validate_dospath(component, len, "AUX", false) ||
1637 0 0 !validate_dospath(component, len, "NUL", false) ||
1638 0 0 !validate_dospath(component, len, "COM", true) ||
1670 6651 578 if (!flags)
1673 4887 577 for (start = c = path->ptr; *c && len < path->size; c++, len++) {
4887 0 for (start = c = path->ptr; *c && len < path->size; c++, len++) {
1674 1 4886 if (!validate_char(*c, flags))
1677 0 4886 if (validate_char_cb && !validate_char_cb(*c, payload))
0 0 if (validate_char_cb && !validate_char_cb(*c, payload))
1680 4660 226 if (*c != '/')
1683 0 226 if (!validate_component(start, (c - start), flags))
1699 0 577 if (path->size != SIZE_MAX && len != path->size)
0 0 if (path->size != SIZE_MAX && len != path->size)
1702 0 577 if (!validate_component(start, (c - start), flags))
1755 0 0 if ((error = git_str_puts(out, path)) < 0)
1758 0 0 for (p = out->ptr; *p; p++) {
1759 0 0 if (*p == '\\')
1774 5 0 p_close(fd) < 0 ||
1775 5 0 p_unlink(path.ptr) < 0 ||
1776 5 0 p_symlink("testing", path.ptr) < 0 ||
1782 5 0 if (path.size)
1943 0 0 if ((error = git__getenv(&uid_str, "SUDO_UID")) == 0 &&
0 0 if ((error = git__getenv(&uid_str, "SUDO_UID")) == 0 &&
1944 0 0 (error = git__strntol64(&uid, uid_str.ptr, uid_str.size, NULL, 10)) == 0 &&
1961 0 123 if (mock_owner) {
1968 0 123 if (p_lstat(path, &st) != 0) {
1969 0 0 if (errno == ENOENT)
1976 123 0 if ((owner_type & GIT_FS_PATH_OWNER_CURRENT_USER) != 0 &&
123 0 if ((owner_type & GIT_FS_PATH_OWNER_CURRENT_USER) != 0 &&
1982 0 0 if ((owner_type & GIT_FS_PATH_OWNER_ADMINISTRATOR) != 0 &&
0 0 if ((owner_type & GIT_FS_PATH_OWNER_ADMINISTRATOR) != 0 &&
1988 0 0 if ((owner_type & GIT_FS_PATH_OWNER_RUNNING_SUDO) != 0 &&
0 0 if ((owner_type & GIT_FS_PATH_OWNER_RUNNING_SUDO) != 0 &&
1989 0 0 euid == 0 &&
1990 0 0 sudo_uid_lookup(&sudo_uid) == 0 &&
2032 0 0 if (git__getenv(&path, "PATH") < 0)
2037 0 0 while (*current_dir) {
2038 0 0 if (! (term = strchr(current_dir, GIT_PATH_LIST_SEPARATOR)))
2043 0 0 git_str_putc(fullpath, '/') < 0 ||
2047 0 0 if (git_fs_path_isfile(fullpath->ptr)) {
2054 0 0 while (*current_dir == GIT_PATH_LIST_SEPARATOR)
2060 0 0 if (found)