Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4fea9cf

Browse files
author
Edward Thomson
committed
iterator: assert tree_iterator has a frame
Although a `tree_iterator` that failed to be properly created does not have a frame, all other `tree_iterator`s should. Do not call `pop` in the failure case, but assert that in all other cases there is a frame.
1 parent a218b2f commit 4fea9cf

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/iterator.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,9 @@ static bool tree_iterator__pop_frame(tree_iterator *ti, bool final)
558558
{
559559
tree_iterator_frame *tf = ti->head;
560560

561-
if (!tf || !tf->up)
561+
assert(tf);
562+
563+
if (!tf->up)
562564
return false;
563565

564566
ti->head = tf->up;
@@ -581,8 +583,9 @@ static void tree_iterator__pop_all(tree_iterator *ti, bool to_end, bool final)
581583
while (tree_iterator__pop_frame(ti, final)) /* pop to root */;
582584

583585
if (!final) {
584-
if(ti->head)
585-
ti->head->current = to_end ? ti->head->n_entries : 0;
586+
assert(ti->head);
587+
588+
ti->head->current = to_end ? ti->head->n_entries : 0;
586589
ti->path_ambiguities = 0;
587590
git_buf_clear(&ti->path);
588591
}
@@ -774,11 +777,12 @@ static void tree_iterator__free(git_iterator *self)
774777
{
775778
tree_iterator *ti = (tree_iterator *)self;
776779

777-
tree_iterator__pop_all(ti, true, false);
778-
779-
if(ti->head)
780+
if (ti->head) {
781+
tree_iterator__pop_all(ti, true, false);
780782
git_tree_free(ti->head->entries[0]->tree);
781-
git__free(ti->head);
783+
git__free(ti->head);
784+
}
785+
782786
git_pool_clear(&ti->pool);
783787
git_buf_free(&ti->path);
784788
}

0 commit comments

Comments
 (0)