Branch Coverage

deps/libgit2/src/path.c
Criterion Covered Total %
branch 265 708 37.4


line true false branch
32 9801 0 if (!(0x80 & (unsigned char)*path))
33 9618 183 return *path && path[1] == ':' ? 2 : 0;
0 9618 return *path && path[1] == ':' ? 2 : 0;
43 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++)
45 0 0 return path[i] == ':' ? i + 1 : 0;
102 19 0 if (path == NULL || *path == '\0') {
0 19 if (path == NULL || *path == '\0') {
110 19 0 while (endp > path && *endp == '/')
0 19 while (endp > path && *endp == '/')
114 0 19 if (endp == path && *endp == '/') {
0 0 if (endp == path && *endp == '/') {
122 76 0 while (startp > path && *(startp - 1) != '/')
57 19 while (startp > path && *(startp - 1) != '/')
131 19 0 if (buffer != NULL && git_buf_set(buffer, startp, len) < 0)
0 19 if (buffer != NULL && git_buf_set(buffer, startp, len) < 0)
175 1306 0 if (path == NULL || *path == '\0') {
0 1306 if (path == NULL || *path == '\0') {
183 1349 0 while (endp > path && *endp == '/')
43 1306 while (endp > path && *endp == '/')
186 0 1306 if (endp - path + 1 > INT_MAX) {
192 0 1306 if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
198 15954 186 while (endp > path && *endp != '/')
14834 1120 while (endp > path && *endp != '/')
202 186 1120 if (endp == path) {
203 0 186 path = (*endp == '/') ? "/" : ".";
210 1120 0 } while (endp > path && *endp == '/');
0 1120 } while (endp > path && *endp == '/');
212 0 1120 if (endp - path + 1 > INT_MAX) {
218 0 1120 if ((len = win32_prefix_length(path, (int)(endp - path + 1))) > 0) {
227 1306 0 if (buffer) {
228 0 1306 if (git_buf_set(buffer, path, len) < 0)
230 0 1306 if (is_prefix && git_buf_putc(buffer, '/') < 0)
0 0 if (is_prefix && git_buf_putc(buffer, '/') < 0)
266 0 0 if (!buffer || buffer->size <= 0)
0 0 if (!buffer || buffer->size <= 0)
271 0 0 if (slash >= 0 && buffer->ptr[slash] == '/')
0 0 if (slash >= 0 && buffer->ptr[slash] == '/')
282 0 0 assert(path);
285 0 0 if (!len || path[len - 1] != '/')
0 0 if (!len || path[len - 1] != '/')
288 0 0 for (i = (ssize_t)len - 2; i >= 0; --i)
289 0 0 if (path[i] == '/')
300 0 9801 if ((prefix_len = dos_drive_prefix_length(path)))
319 1705 8096 if (path[offset] == '/')
328 0 456 assert(ceiling >= 0);
330 912 0 while (path->size > (size_t)ceiling) {
331 456 456 if (path->ptr[path->size-1] != '/')
344 2296 0 assert(path && path_out);
0 2296 assert(path && path_out);
348 2268 28 if (base != NULL && root < 0) {
2094 174 if (base != NULL && root < 0) {
349 0 2094 if (git_buf_joinpath(path_out, base, path) < 0)
354 0 202 if (git_buf_sets(path_out, path) < 0)
357 0 202 if (root < 0)
359 174 28 else if (base)
363 1567 729 if (root_at)
373 0 19 if (path->size == 0)
376 268 19 for (p = path->ptr, q = path->ptr; *q; p++, q++) {
379 27 241 while (*q == '/' && *(q+1) == '/') {
0 27 while (*q == '/' && *(q+1) == '/') {
392 68 0 assert(path && path_out);
0 68 assert(path && path_out);
395 4 64 if (base != NULL && git_path_root(path) < 0) {
0 4 if (base != NULL && git_path_root(path) < 0) {
396 0 0 if (git_buf_joinpath(path_out, base, path) < 0)
401 0 68 if (p_realpath(path, buf) == NULL) {
403 0 0 int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
0 0 int error = (errno == ENOENT || errno == ENOTDIR) ? GIT_ENOTFOUND : -1;
417 23 0 return (error < 0) ? error : git_path_to_dir(path_out);
423 2411 1660 git_buf_len(path) > 0 &&
427 0 4257 return git_buf_oom(path) ? -1 : 0;
434 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) {
443 3 0 assert(decoded_out && input);
0 3 assert(decoded_out && input);
448 150 3 for(i = 0; i < len; i++)
452 150 0 if (c != '%')
455 0 0 if (i >= len - 2)
461 0 0 if (hi < 0 || lo < 0)
0 0 if (hi < 0 || lo < 0)
468 0 150 if (git_buf_putc(decoded_out, c) < 0)
485 6 3 if (git__prefixcmp(file_url, "file://") == 0) {
486 6 0 if (file_url[7] == '/')
488 0 0 else if (git__prefixcmp(file_url + 7, "localhost/") == 0)
504 3 0 assert(local_path_out && file_url);
0 3 assert(local_path_out && file_url);
506 3 0 if ((offset = local_file_url_prefixlen(file_url)) < 0 ||
3 0 if ((offset = local_file_url_prefixlen(file_url)) < 0 ||
507 0 3 file_url[offset] == '\0' || file_url[offset] == '/')
529 777 0 assert(path && cb);
0 777 assert(path && cb);
531 777 0 if (ceiling != NULL) {
532 777 0 if (git__prefixcmp(path->ptr, ceiling) == 0)
540 0 777 if (!scan) {
542 0 0 if (error)
551 923 751 while (scan >= stop) {
555 26 897 if (error) {
561 897 0 if (scan >= 0) {
569 777 0 if (scan >= 0)
573 751 26 if (!error && stop == 0 && iter.ptr[0] != '/') {
0 751 if (!error && stop == 0 && iter.ptr[0] != '/') {
0 0 if (!error && stop == 0 && iter.ptr[0] != '/') {
575 0 0 if (error)
584 0 2880 assert(path);
591 336 1575 if (p_stat(path, &st) < 0)
601 0 648 assert(path);
602 454 194 if (p_stat(path, &st) < 0)
612 0 0 assert(path);
613 0 0 if (p_lstat(path, &st) < 0)
675 0 2 if (!git_path_isdir(path))
678 0 2 if ((error = git_buf_sets(&dir, path)) != 0)
719 1229 0 if (p_lstat(path, st) == 0)
736 0 509 if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) ||
0 509 if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, dir_size, sub_size) ||
737 0 509 GIT_ADD_SIZET_OVERFLOW(&alloc_size, alloc_size, 2) ||
742 0 509 if (git_buf_joinpath(dir, dir->ptr, sub) < 0)
771 565 0 if (!error) {
773 547 18 if (p_realpath(dir->ptr, buf) != NULL)
778 565 0 if (!error) /* && git_path_isdir(dir->ptr) == false) */
779 0 565 error = (git_path_dirname_r(dir, dir->ptr) < 0) ? -1 : 0;
781 565 0 if (!error)
792 186 0 GIT_ERROR_CHECK_ALLOC_BUF(path);
0 186 GIT_ERROR_CHECK_ALLOC_BUF(path);
794 0 186 if (ceiling > path->size)
798 186 0 if (ceiling == 0)
802 186 0 if (ceiling == 0) {
803 186 0 for (next = path->ptr; *next && git__isalpha(*next); ++next);
0 186 for (next = path->ptr; *next && git__isalpha(*next); ++next);
804 0 186 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] == '/')
810 186 186 while (*from) {
811 186 186 for (next = from; *next && *next != '/'; ++next);
186 0 for (next = from; *next && *next != '/'; ++next);
815 186 0 if (len == 1 && from[0] == '.')
186 0 if (len == 1 && from[0] == '.')
818 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] == '.') {
820 0 0 if (to == base && ceiling != 0) {
0 0 if (to == base && ceiling != 0) {
828 0 0 if (to == base) {
829 0 0 if (*next == '/')
832 0 0 if (to != from)
841 0 0 while (to > base && to[-1] == '/') to--;
0 0 while (to > base && to[-1] == '/') to--;
842 0 0 while (to > base && to[-1] != '/') to--;
0 0 while (to > base && to[-1] != '/') to--;
845 0 0 if (*next == '/' && *from != '/')
0 0 if (*next == '/' && *from != '/')
848 0 0 if (to != from)
856 0 186 while (*from == '/') from++;
882 137 83 if (cmp)
888 34 49 if (c1 == '\0' && isdir1)
1 33 if (c1 == '\0' && isdir1)
891 49 34 if (c2 == '\0' && isdir2)
2 47 if (c2 == '\0' && isdir2)
894 48 35 return (c1 < c2) ? -1 : (c1 > c2) ? 1 : 0;
901 166 8 for (p = one, q = two; *p && *q; p++, q++) {
166 0 for (p = one, q = two; *p && *q; p++, q++) {
902 28 138 if (*p == '/' && *q == '/')
28 0 if (*p == '/' && *q == '/')
904 14 124 else if (*p != *q)
908 21 1 return dirsep ? (dirsep - one) + 1 : 0;
916 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++) {
917 0 0 if (*p == '/' && *q == '/') {
0 0 if (*p == '/' && *q == '/') {
921 0 0 else if (*p != *q)
926 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) &&
927 0 0 (*p_dirsep != '/' || *q_dirsep != '/')) {
933 0 0 if (*p == '/' && !*q)
0 0 if (*p == '/' && !*q)
935 0 0 else if (!*p && *q == '/')
0 0 else if (!*p && *q == '/')
937 0 0 else if (!*p && !*q)
0 0 else if (!*p && !*q)
946 0 0 if (!*q)
949 0 0 for (; (q = strchr(q, '/')) && *(q + 1); q++)
0 0 for (; (q = strchr(q, '/')) && *(q + 1); q++)
952 0 0 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3);
0 0 GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newlen, depth, 3);
953 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&newlen, newlen, plen);
955 0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1);
0 0 GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, newlen, 1);
959 0 0 if (git_buf_try_grow(path, alloclen, 1) < 0)
965 0 0 for (i = 0; i < depth; i++)
976 0 0 for (end = scan + pathlen; scan < end; ++scan)
977 0 0 if (*scan & 0x80)
1138 0 338 if (git_path_to_dir(path) < 0)
1143 0 338 if ((dir = opendir(path->ptr)) == NULL) {
1145 0 0 if (errno == ENOENT)
1156 947 336 while ((de = readdir(dir)) != NULL) {
1160 672 275 if (git_path_is_dot_or_dotdot(de_path))
1168 0 275 if ((error = git_buf_put(path, de_path, de_len)) < 0)
1177 2 273 if (error != 0) {
1178 2 0 if (!git_error_last())
1364 456 0 assert(diriter && path);
0 456 assert(diriter && path);
1368 0 456 if (git_buf_puts(&diriter->path, path) < 0)
1373 0 456 if (diriter->path.size == 0) {
1378 2 454 if ((diriter->dir = opendir(diriter->path.ptr)) == NULL) {
1404 0 1704 assert(diriter);
1409 454 2158 if ((de = readdir(diriter->dir)) == NULL) {
1410 454 0 if (!errno)
1417 2158 0 } while (skip_dot && git_path_is_dot_or_dotdot(de->d_name));
908 1250 } while (skip_dot && git_path_is_dot_or_dotdot(de->d_name));
1430 1250 0 if (diriter->parent_len > 0 &&
1250 0 if (diriter->parent_len > 0 &&
1436 0 1250 if (git_buf_oom(&diriter->path))
1447 0 0 assert(out && out_len && diriter);
0 0 assert(out && out_len && diriter);
0 0 assert(out && out_len && diriter);
1449 0 0 assert(diriter->path.size > diriter->parent_len);
1461 1250 0 assert(out && out_len && diriter);
1250 0 assert(out && out_len && diriter);
0 1250 assert(out && out_len && diriter);
1470 1113 0 assert(out && diriter);
0 1113 assert(out && diriter);
1477 0 456 if (diriter == NULL)
1480 454 2 if (diriter->dir) {
1506 2 0 assert(contents && path);
0 2 assert(contents && path);
1508 0 2 if ((error = git_path_diriter_init(&iter, path, flags)) < 0)
1511 4 2 while ((error = git_path_diriter_next(&iter)) == 0) {
1512 0 4 if ((error = git_path_diriter_fullpath(&name, &name_len, &iter)) < 0)
1515 0 4 assert(name_len > prefix_len);
1518 0 4 GIT_ERROR_CHECK_ALLOC(dup);
1520 0 4 if ((error = git_vector_insert(contents, dup)) < 0)
1524 2 0 if (error == GIT_ITEROVER)
1533 3 3 if (git_path_is_local_file_url(url_or_path))
1548 0 0 size_t last = trailing_num ? 4 : 3;
1550 0 0 if (len < last || git__strncasecmp(component, dospath, 3) != 0)
0 0 if (len < last || git__strncasecmp(component, dospath, 3) != 0)
1553 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'))
1556 0 0 return (len > last &&
1557 0 0 component[last] != '.' &&
0 0 component[last] != '.' &&
1563 0 0 while (*len) {
1566 0 0 if (cp_len < 0)
1573 0 0 switch (codepoint) {
1607 0 0 if (next_hfs_char(&path, &len) != '.')
1610 0 0 for (i = 0; i < needle_len; i++) {
1612 0 0 if (c != needle[i])
1616 0 0 if (next_hfs_char(&path, &len) != '\0')
1633 370 165 if (repo)
1636 1057 522 for (i = 0; i < reserved_len; i++) {
1639 836 221 if (len >= r->size &&
13 823 if (len >= r->size &&
1646 522 13 if (!start)
1654 13 0 if (path[start] == '\\' || path[start] == ':')
0 13 if (path[start] == '\\' || path[start] == ':')
1658 13 0 for (i = start; i < len; i++) {
1659 13 0 if (path[i] != ' ' && path[i] != '.')
13 0 if (path[i] != ' ' && path[i] != '.')
1680 0 0 if (*c == '\0' || *c == ':')
0 0 if (*c == '\0' || *c == ':')
1682 0 0 if (*c != ' ' && *c != '.')
0 0 if (*c != ' ' && *c != '.')
1693 0 0 if (name[0] == '.' && len >= dotgit_len &&
0 0 if (name[0] == '.' && len >= dotgit_len &&
0 0 if (name[0] == '.' && len >= dotgit_len &&
1699 0 0 if (!strncasecmp(name, dotgit_name, 6) && name[6] == '~' &&
0 0 if (!strncasecmp(name, dotgit_name, 6) && name[6] == '~' &&
0 0 if (!strncasecmp(name, dotgit_name, 6) && name[6] == '~' &&
1700 0 0 name[7] >= '1' && name[7] <= '4')
1704 0 0 for (i = 0, saw_tilde = 0; i < 8; i++) {
1705 0 0 if (name[i] == '\0') {
1707 0 0 } else if (saw_tilde) {
1708 0 0 if (name[i] < '0' || name[i] > '9')
0 0 if (name[i] < '0' || name[i] > '9')
1710 0 0 } else if (name[i] == '~') {
1711 0 0 if (name[i+1] < '1' || name[i+1] > '9')
0 0 if (name[i+1] < '1' || name[i+1] > '9')
1714 0 0 } else if (i >= 6) {
1716 0 0 } else if ((unsigned char)name[i] > 127) {
1718 0 0 } else if (git__tolower(name[i]) != shortname_pfix[i]) {
1728 0 4919 if ((flags & GIT_PATH_REJECT_BACKSLASH) && c == '\\')
0 0 if ((flags & GIT_PATH_REJECT_BACKSLASH) && c == '\\')
1731 1170 3749 if ((flags & GIT_PATH_REJECT_SLASH) && c == '/')
1 1169 if ((flags & GIT_PATH_REJECT_SLASH) && c == '/')
1734 0 4918 if (flags & GIT_PATH_REJECT_NT_CHARS) {
1735 0 0 if (c < 32)
1738 0 0 switch (c) {
1761 0 0 while (len >0 && tolower(*str) == tolower(*prefix)) {
0 0 while (len >0 && tolower(*str) == tolower(*prefix)) {
1787 0 803 if (len == 0)
1790 803 0 if ((flags & GIT_PATH_REJECT_TRAVERSAL) &&
7 796 if ((flags & GIT_PATH_REJECT_TRAVERSAL) &&
1791 0 7 len == 1 && component[0] == '.')
1794 803 0 if ((flags & GIT_PATH_REJECT_TRAVERSAL) &&
0 803 if ((flags & GIT_PATH_REJECT_TRAVERSAL) &&
1795 0 0 len == 2 && component[0] == '.' && component[1] == '.')
0 0 len == 2 && component[0] == '.' && component[1] == '.')
1798 0 803 if ((flags & GIT_PATH_REJECT_TRAILING_DOT) && component[len-1] == '.')
0 0 if ((flags & GIT_PATH_REJECT_TRAILING_DOT) && component[len-1] == '.')
1801 0 803 if ((flags & GIT_PATH_REJECT_TRAILING_SPACE) && component[len-1] == ' ')
0 0 if ((flags & GIT_PATH_REJECT_TRAILING_SPACE) && component[len-1] == ' ')
1804 0 803 if ((flags & GIT_PATH_REJECT_TRAILING_COLON) && component[len-1] == ':')
0 0 if ((flags & GIT_PATH_REJECT_TRAILING_COLON) && component[len-1] == ':')
1807 0 803 if (flags & GIT_PATH_REJECT_DOS_PATHS) {
1809 0 0 !verify_dospath(component, len, "PRN", false) ||
1810 0 0 !verify_dospath(component, len, "AUX", false) ||
1811 0 0 !verify_dospath(component, len, "NUL", false) ||
1812 0 0 !verify_dospath(component, len, "COM", true) ||
1817 0 803 if (flags & GIT_PATH_REJECT_DOT_GIT_HFS) {
1818 0 0 if (!verify_dotgit_hfs(component, len))
1820 0 0 if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS))
0 0 if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS))
1824 535 268 if (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) {
1825 0 535 if (!verify_dotgit_ntfs(repo, component, len))
1827 0 535 if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS))
0 0 if (S_ISLNK(mode) && git_path_is_gitfile(component, len, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_NTFS))
1834 803 0 if ((flags & GIT_PATH_REJECT_DOT_GIT_HFS) == 0 &&
268 535 if ((flags & GIT_PATH_REJECT_DOT_GIT_HFS) == 0 &&
1835 0 268 (flags & GIT_PATH_REJECT_DOT_GIT_NTFS) == 0 &&
1837 0 0 if (len >= 4 &&
0 0 if (len >= 4 &&
1838 0 0 component[0] == '.' &&
1839 0 0 (component[1] == 'g' || component[1] == 'G') &&
0 0 (component[1] == 'g' || component[1] == 'G') &&
1840 0 0 (component[2] == 'i' || component[2] == 'I') &&
0 0 (component[2] == 'i' || component[2] == 'I') &&
1841 0 0 (component[3] == 't' || component[3] == 'T')) {
1842 0 0 if (len == 4)
1845 0 0 if (S_ISLNK(mode) && common_prefix_icase(component, len, ".gitmodules") == len)
0 0 if (S_ISLNK(mode) && common_prefix_icase(component, len, ".gitmodules") == len)
1866 351 112 if (repo && !protectHFS)
351 0 if (repo && !protectHFS)
1868 463 0 if (!error && protectHFS)
0 463 if (!error && protectHFS)
1871 351 112 if (repo)
1873 463 0 if (!error && protectNTFS)
463 0 if (!error && protectNTFS)
1888 463 115 if ((flags & GIT_PATH_REJECT_DOT_GIT))
1891 4919 577 for (start = c = path; *c; c++) {
1892 1 4918 if (!verify_char(*c, flags))
1895 226 4692 if (*c == '/') {
1896 0 226 if (!verify_component(repo, start, (c - start), mode, flags))
1911 0 0 if ((error = git_buf_puts(out, path)) < 0)
1914 0 0 for (p = out->ptr; *p; p++) {
1915 0 0 if (*p == '\\')
1937 0 0 if (!(gitfile >= GIT_PATH_GITFILE_GITIGNORE && gitfile < ARRAY_SIZE(gitfiles))) {
1968 5 0 p_close(fd) < 0 ||
1969 5 0 p_unlink(path.ptr) < 0 ||
1970 5 0 p_symlink("testing", path.ptr) < 0 ||
1976 5 0 if (path.size)