iterator: use GIT_ASSERT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
diff --git a/src/diff_generate.c b/src/diff_generate.c
index f021a26..745e5ae 100644
--- a/src/diff_generate.c
+++ b/src/diff_generate.c
@@ -1206,8 +1206,9 @@ int git_diff__from_iterators(
/* make iterators have matching icase behavior */
if (DIFF_FLAG_IS_SET(diff, GIT_DIFF_IGNORE_CASE)) {
- git_iterator_set_ignore_case(old_iter, true);
- git_iterator_set_ignore_case(new_iter, true);
+ if ((error = git_iterator_set_ignore_case(old_iter, true)) < 0 ||
+ (error = git_iterator_set_ignore_case(new_iter, true)) < 0)
+ goto cleanup;
}
/* finish initialization */
diff --git a/src/iterator.c b/src/iterator.c
index a393187..0734595 100644
--- a/src/iterator.c
+++ b/src/iterator.c
@@ -330,7 +330,7 @@ static iterator_pathlist_search_t iterator_pathlist_search(
break;
/* an exact match would have been matched by the bsearch above */
- assert(p[path_len]);
+ GIT_ASSERT_WITH_RETVAL(p[path_len], ITERATOR_PATHLIST_NONE);
/* is this a literal directory entry (eg `foo/`) or a file beneath */
if (p[path_len] == '/') {
@@ -678,14 +678,14 @@ done:
return error;
}
-static void tree_iterator_frame_pop(tree_iterator *iter)
+static int tree_iterator_frame_pop(tree_iterator *iter)
{
tree_iterator_frame *frame;
git_buf *buf = NULL;
git_tree *tree;
size_t i;
- assert(iter->frames.size);
+ GIT_ASSERT(iter->frames.size);
frame = git_array_pop(iter->frames);
@@ -705,6 +705,8 @@ static void tree_iterator_frame_pop(tree_iterator *iter)
git_vector_free(&frame->similar_trees);
git_buf_dispose(&frame->path);
+
+ return 0;
}
static int tree_iterator_current(
@@ -760,7 +762,9 @@ static int tree_iterator_advance(const git_index_entry **out, git_iterator *i)
/* no more entries in this frame. pop the frame out */
if (frame->next_idx == frame->entries.length) {
- tree_iterator_frame_pop(iter);
+ if ((error = tree_iterator_frame_pop(iter)) < 0)
+ break;
+
continue;
}
@@ -838,7 +842,7 @@ static int tree_iterator_advance_into(
const git_index_entry **out, git_iterator *i)
{
tree_iterator *iter = (tree_iterator *)i;
- tree_iterator_frame *frame;
+ tree_iterator_frame *frame;
tree_iterator_entry *prev_entry;
int error;
@@ -855,7 +859,7 @@ static int tree_iterator_advance_into(
* we will have pushed a new (empty) frame on to the stack for this
* new directory. since it's empty, its current_entry should be null.
*/
- assert(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
+ GIT_ASSERT(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
if (prev_entry) {
if (!git_tree_entry__is_tree(prev_entry->tree_entry))
@@ -973,7 +977,7 @@ int git_iterator_current_tree_entry(
tree_iterator_frame *frame;
tree_iterator_entry *entry;
- assert(i->type == GIT_ITERATOR_TREE);
+ GIT_ASSERT(i->type == GIT_ITERATOR_TREE);
iter = (tree_iterator *)i;
@@ -990,11 +994,11 @@ int git_iterator_current_parent_tree(
tree_iterator *iter;
tree_iterator_frame *frame;
- assert(i->type == GIT_ITERATOR_TREE);
+ GIT_ASSERT(i->type == GIT_ITERATOR_TREE);
iter = (tree_iterator *)i;
- assert(depth < iter->frames.size);
+ GIT_ASSERT(depth < iter->frames.size);
frame = &iter->frames.ptr[iter->frames.size-depth-1];
*parent_tree = frame->tree;
@@ -1388,7 +1392,7 @@ static int filesystem_iterator_frame_push(
if ((error = git_path_diriter_fullpath(&path, &path_len, &diriter)) < 0)
goto done;
- assert(path_len > iter->root_len);
+ GIT_ASSERT(path_len > iter->root_len);
/* remove the prefix if requested */
path += iter->root_len;
@@ -1469,17 +1473,19 @@ done:
return error;
}
-GIT_INLINE(void) filesystem_iterator_frame_pop(filesystem_iterator *iter)
+GIT_INLINE(int) filesystem_iterator_frame_pop(filesystem_iterator *iter)
{
filesystem_iterator_frame *frame;
- assert(iter->frames.size);
+ GIT_ASSERT(iter->frames.size);
frame = git_array_pop(iter->frames);
filesystem_iterator_frame_pop_ignores(iter);
git_pool_clear(&frame->entry_pool);
git_vector_free(&frame->entries);
+
+ return 0;
}
static void filesystem_iterator_set_current(
@@ -1646,7 +1652,7 @@ static int filesystem_iterator_advance_into(
* we will have pushed a new (empty) frame on to the stack for this
* new directory. since it's empty, its current_entry should be null.
*/
- assert(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
+ GIT_ASSERT(iterator__do_autoexpand(i) ^ (prev_entry != NULL));
if (prev_entry) {
if (prev_entry->st.st_mode != GIT_FILEMODE_COMMIT &&
@@ -1762,12 +1768,13 @@ static int filesystem_iterator_advance_over(
*out = NULL;
*status = GIT_ITERATOR_STATUS_NORMAL;
- assert(iterator__has_been_accessed(i));
+ GIT_ASSERT(iterator__has_been_accessed(i));
current_frame = filesystem_iterator_current_frame(iter);
- assert(current_frame);
+ GIT_ASSERT(current_frame);
+
current_entry = filesystem_iterator_current_entry(current_frame);
- assert(current_entry);
+ GIT_ASSERT(current_entry);
if ((error = git_iterator_current(&entry, i)) < 0)
return error;
@@ -2065,8 +2072,8 @@ static bool index_iterator_create_pseudotree(
static int index_iterator_skip_pseudotree(index_iterator *iter)
{
- assert(iterator__has_been_accessed(&iter->base));
- assert(S_ISDIR(iter->entry->mode));
+ GIT_ASSERT(iterator__has_been_accessed(&iter->base));
+ GIT_ASSERT(S_ISDIR(iter->entry->mode));
while (true) {
const git_index_entry *next_entry = NULL;
@@ -2280,10 +2287,11 @@ int git_iterator_reset_range(
return i->cb->reset(i);
}
-void git_iterator_set_ignore_case(git_iterator *i, bool ignore_case)
+int git_iterator_set_ignore_case(git_iterator *i, bool ignore_case)
{
- assert(!iterator__has_been_accessed(i));
+ GIT_ASSERT(!iterator__has_been_accessed(i));
iterator_set_ignore_case(i, ignore_case);
+ return 0;
}
void git_iterator_free(git_iterator *iter)
diff --git a/src/iterator.h b/src/iterator.h
index ebd6936..30465df 100644
--- a/src/iterator.h
+++ b/src/iterator.h
@@ -263,7 +263,7 @@ GIT_INLINE(bool) git_iterator_ignore_case(git_iterator *iter)
return ((iter->flags & GIT_ITERATOR_IGNORE_CASE) != 0);
}
-extern void git_iterator_set_ignore_case(
+extern int git_iterator_set_ignore_case(
git_iterator *iter, bool ignore_case);
extern int git_iterator_current_tree_entry(