Commit 16b1a756 by Edward Thomson

path: use GIT_ASSERT

parent 2cfa31c4
...@@ -307,7 +307,9 @@ int git_path_root(const char *path) ...@@ -307,7 +307,9 @@ int git_path_root(const char *path)
static void path_trim_slashes(git_buf *path) static void path_trim_slashes(git_buf *path)
{ {
int ceiling = git_path_root(path->ptr) + 1; int ceiling = git_path_root(path->ptr) + 1;
assert(ceiling >= 0);
if (ceiling < 0)
return;
while (path->size > (size_t)ceiling) { while (path->size > (size_t)ceiling) {
if (path->ptr[path->size-1] != '/') if (path->ptr[path->size-1] != '/')
...@@ -323,7 +325,8 @@ int git_path_join_unrooted( ...@@ -323,7 +325,8 @@ int git_path_join_unrooted(
{ {
ssize_t root; ssize_t root;
assert(path && path_out); GIT_ASSERT_ARG(path_out);
GIT_ASSERT_ARG(path);
root = (ssize_t)git_path_root(path); root = (ssize_t)git_path_root(path);
...@@ -371,7 +374,8 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base) ...@@ -371,7 +374,8 @@ int git_path_prettify(git_buf *path_out, const char *path, const char *base)
{ {
char buf[GIT_PATH_MAX]; char buf[GIT_PATH_MAX];
assert(path && path_out); GIT_ASSERT_ARG(path_out);
GIT_ASSERT_ARG(path);
/* construct path if needed */ /* construct path if needed */
if (base != NULL && git_path_root(path) < 0) { if (base != NULL && git_path_root(path) < 0) {
...@@ -422,7 +426,9 @@ void git_path_string_to_dir(char* path, size_t size) ...@@ -422,7 +426,9 @@ void git_path_string_to_dir(char* path, size_t size)
int git__percent_decode(git_buf *decoded_out, const char *input) int git__percent_decode(git_buf *decoded_out, const char *input)
{ {
int len, hi, lo, i; int len, hi, lo, i;
assert(decoded_out && input);
GIT_ASSERT_ARG(decoded_out);
GIT_ASSERT_ARG(input);
len = (int)strlen(input); len = (int)strlen(input);
git_buf_clear(decoded_out); git_buf_clear(decoded_out);
...@@ -483,7 +489,8 @@ int git_path_fromurl(git_buf *local_path_out, const char *file_url) ...@@ -483,7 +489,8 @@ int git_path_fromurl(git_buf *local_path_out, const char *file_url)
{ {
int offset; int offset;
assert(local_path_out && file_url); GIT_ASSERT_ARG(local_path_out);
GIT_ASSERT_ARG(file_url);
if ((offset = local_file_url_prefixlen(file_url)) < 0 || if ((offset = local_file_url_prefixlen(file_url)) < 0 ||
file_url[offset] == '\0' || file_url[offset] == '/') file_url[offset] == '\0' || file_url[offset] == '/')
...@@ -508,7 +515,8 @@ int git_path_walk_up( ...@@ -508,7 +515,8 @@ int git_path_walk_up(
ssize_t stop = 0, scan; ssize_t stop = 0, scan;
char oldc = '\0'; char oldc = '\0';
assert(path && cb); GIT_ASSERT_ARG(path);
GIT_ASSERT_ARG(cb);
if (ceiling != NULL) { if (ceiling != NULL) {
if (git__prefixcmp(path->ptr, ceiling) == 0) if (git__prefixcmp(path->ptr, ceiling) == 0)
...@@ -563,7 +571,7 @@ int git_path_walk_up( ...@@ -563,7 +571,7 @@ int git_path_walk_up(
bool git_path_exists(const char *path) bool git_path_exists(const char *path)
{ {
assert(path); GIT_ASSERT_ARG_WITH_RETVAL(path, false);
return p_access(path, F_OK) == 0; return p_access(path, F_OK) == 0;
} }
...@@ -580,7 +588,7 @@ bool git_path_isfile(const char *path) ...@@ -580,7 +588,7 @@ bool git_path_isfile(const char *path)
{ {
struct stat st; struct stat st;
assert(path); GIT_ASSERT_ARG_WITH_RETVAL(path, false);
if (p_stat(path, &st) < 0) if (p_stat(path, &st) < 0)
return false; return false;
...@@ -591,7 +599,7 @@ bool git_path_islink(const char *path) ...@@ -591,7 +599,7 @@ bool git_path_islink(const char *path)
{ {
struct stat st; struct stat st;
assert(path); GIT_ASSERT_ARG_WITH_RETVAL(path, false);
if (p_lstat(path, &st) < 0) if (p_lstat(path, &st) < 0)
return false; return false;
...@@ -1193,7 +1201,8 @@ int git_path_diriter_init( ...@@ -1193,7 +1201,8 @@ int git_path_diriter_init(
if (is_win7_or_later < 0) if (is_win7_or_later < 0)
is_win7_or_later = git_has_win32_version(6, 1, 0); is_win7_or_later = git_has_win32_version(6, 1, 0);
assert(diriter && path); GIT_ASSERT_ARG(diriter);
GIT_ASSERT_ARG(path);
memset(diriter, 0, sizeof(git_path_diriter)); memset(diriter, 0, sizeof(git_path_diriter));
diriter->handle = INVALID_HANDLE_VALUE; diriter->handle = INVALID_HANDLE_VALUE;
...@@ -1293,9 +1302,10 @@ int git_path_diriter_filename( ...@@ -1293,9 +1302,10 @@ int git_path_diriter_filename(
size_t *out_len, size_t *out_len,
git_path_diriter *diriter) git_path_diriter *diriter)
{ {
assert(out && out_len && diriter); GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(out_len);
assert(diriter->path_utf8.size > diriter->parent_utf8_len); GIT_ASSERT_ARG(diriter);
GIT_ASSERT(diriter->path_utf8.size > diriter->parent_utf8_len);
*out = &diriter->path_utf8.ptr[diriter->parent_utf8_len+1]; *out = &diriter->path_utf8.ptr[diriter->parent_utf8_len+1];
*out_len = diriter->path_utf8.size - diriter->parent_utf8_len - 1; *out_len = diriter->path_utf8.size - diriter->parent_utf8_len - 1;
...@@ -1307,7 +1317,9 @@ int git_path_diriter_fullpath( ...@@ -1307,7 +1317,9 @@ int git_path_diriter_fullpath(
size_t *out_len, size_t *out_len,
git_path_diriter *diriter) git_path_diriter *diriter)
{ {
assert(out && out_len && diriter); GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(out_len);
GIT_ASSERT_ARG(diriter);
*out = diriter->path_utf8.ptr; *out = diriter->path_utf8.ptr;
*out_len = diriter->path_utf8.size; *out_len = diriter->path_utf8.size;
...@@ -1316,7 +1328,8 @@ int git_path_diriter_fullpath( ...@@ -1316,7 +1328,8 @@ int git_path_diriter_fullpath(
int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter) int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter)
{ {
assert(out && diriter); GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(diriter);
return git_win32__file_attribute_to_stat(out, return git_win32__file_attribute_to_stat(out,
(WIN32_FILE_ATTRIBUTE_DATA *)&diriter->current, (WIN32_FILE_ATTRIBUTE_DATA *)&diriter->current,
...@@ -1343,7 +1356,8 @@ int git_path_diriter_init( ...@@ -1343,7 +1356,8 @@ int git_path_diriter_init(
const char *path, const char *path,
unsigned int flags) unsigned int flags)
{ {
assert(diriter && path); GIT_ASSERT_ARG(diriter);
GIT_ASSERT_ARG(path);
memset(diriter, 0, sizeof(git_path_diriter)); memset(diriter, 0, sizeof(git_path_diriter));
...@@ -1383,7 +1397,7 @@ int git_path_diriter_next(git_path_diriter *diriter) ...@@ -1383,7 +1397,7 @@ int git_path_diriter_next(git_path_diriter *diriter)
bool skip_dot = !(diriter->flags & GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT); bool skip_dot = !(diriter->flags & GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT);
int error = 0; int error = 0;
assert(diriter); GIT_ASSERT_ARG(diriter);
errno = 0; errno = 0;
...@@ -1426,9 +1440,10 @@ int git_path_diriter_filename( ...@@ -1426,9 +1440,10 @@ int git_path_diriter_filename(
size_t *out_len, size_t *out_len,
git_path_diriter *diriter) git_path_diriter *diriter)
{ {
assert(out && out_len && diriter); GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(out_len);
assert(diriter->path.size > diriter->parent_len); GIT_ASSERT_ARG(diriter);
GIT_ASSERT(diriter->path.size > diriter->parent_len);
*out = &diriter->path.ptr[diriter->parent_len+1]; *out = &diriter->path.ptr[diriter->parent_len+1];
*out_len = diriter->path.size - diriter->parent_len - 1; *out_len = diriter->path.size - diriter->parent_len - 1;
...@@ -1440,7 +1455,9 @@ int git_path_diriter_fullpath( ...@@ -1440,7 +1455,9 @@ int git_path_diriter_fullpath(
size_t *out_len, size_t *out_len,
git_path_diriter *diriter) git_path_diriter *diriter)
{ {
assert(out && out_len && diriter); GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(out_len);
GIT_ASSERT_ARG(diriter);
*out = diriter->path.ptr; *out = diriter->path.ptr;
*out_len = diriter->path.size; *out_len = diriter->path.size;
...@@ -1449,7 +1466,8 @@ int git_path_diriter_fullpath( ...@@ -1449,7 +1466,8 @@ int git_path_diriter_fullpath(
int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter) int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter)
{ {
assert(out && diriter); GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(diriter);
return git_path_lstat(diriter->path.ptr, out); return git_path_lstat(diriter->path.ptr, out);
} }
...@@ -1485,7 +1503,8 @@ int git_path_dirload( ...@@ -1485,7 +1503,8 @@ int git_path_dirload(
char *dup; char *dup;
int error; int error;
assert(contents && path); GIT_ASSERT_ARG(contents);
GIT_ASSERT_ARG(path);
if ((error = git_path_diriter_init(&iter, path, flags)) < 0) if ((error = git_path_diriter_init(&iter, path, flags)) < 0)
return error; return error;
...@@ -1494,7 +1513,7 @@ int git_path_dirload( ...@@ -1494,7 +1513,7 @@ int git_path_dirload(
if ((error = git_path_diriter_fullpath(&name, &name_len, &iter)) < 0) if ((error = git_path_diriter_fullpath(&name, &name_len, &iter)) < 0)
break; break;
assert(name_len > prefix_len); GIT_ASSERT(name_len > prefix_len);
dup = git__strndup(name + prefix_len, name_len - prefix_len); dup = git__strndup(name + prefix_len, name_len - prefix_len);
GIT_ERROR_CHECK_ALLOC(dup); GIT_ERROR_CHECK_ALLOC(dup);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment