Skip to content

Commit cd49f9b

Browse files
committed
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()
2 parents 4b945ee + 5a8e7c3 commit cd49f9b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

notes.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
153153
* How to consolidate an int_node:
154154
* If there are > 1 non-NULL entries, give up and return non-zero.
155155
* Otherwise replace the int_node at the given index in the given parent node
156-
* with the only entry (or a NULL entry if no entries) from the given tree,
157-
* and return 0.
156+
* with the only NOTE entry (or a NULL entry if no entries) from the given
157+
* tree, and return 0.
158158
*/
159159
static int note_tree_consolidate(struct int_node *tree,
160160
struct int_node *parent, unsigned char index)
@@ -173,6 +173,8 @@ static int note_tree_consolidate(struct int_node *tree,
173173
}
174174
}
175175

176+
if (p && (GET_PTR_TYPE(p) != PTR_TYPE_NOTE))
177+
return -2;
176178
/* replace tree with p in parent[index] */
177179
parent->a[index] = p;
178180
free(tree);

0 commit comments

Comments
 (0)