summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2017-03-30 14:07:17 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2017-03-30 14:07:17 -0700
commitcd49f9bfb8c23621f618d110f2b95853728be2ba (patch)
tree22017f845d1706a6e68659b0a5ceefd38def4395
parentMerge branch 'js/rebase-i-reword-to-run-hooks' (diff)
parentnotes: do not break note_tree structure in note_tree_consolidate() (diff)
downloadtgif-cd49f9bfb8c23621f618d110f2b95853728be2ba.tar.xz
Merge branch 'mh/notes-tree-consolidate-fix'
Removing an entry from a notes tree and then looking another note entry from the resulting tree using the internal notes API functions did not work as expected. No in-tree users of the API has such access pattern, but it still is worth fixing. * mh/notes-tree-consolidate-fix: notes: do not break note_tree structure in note_tree_consolidate()
-rw-r--r--notes.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/notes.c b/notes.c
index 2bab961ac1..542563b280 100644
--- a/notes.c
+++ b/notes.c
@@ -153,8 +153,8 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
* How to consolidate an int_node:
* If there are > 1 non-NULL entries, give up and return non-zero.
* Otherwise replace the int_node at the given index in the given parent node
- * with the only entry (or a NULL entry if no entries) from the given tree,
- * and return 0.
+ * with the only NOTE entry (or a NULL entry if no entries) from the given
+ * tree, and return 0.
*/
static int note_tree_consolidate(struct int_node *tree,
struct int_node *parent, unsigned char index)
@@ -173,6 +173,8 @@ static int note_tree_consolidate(struct int_node *tree,
}
}
+ if (p && (GET_PTR_TYPE(p) != PTR_TYPE_NOTE))
+ return -2;
/* replace tree with p in parent[index] */
parent->a[index] = p;
free(tree);