Commit 42390c5e authored by Warren Dukes's avatar Warren Dukes

fix a bug when deleting songs and CHILDREN_PER_NODE > 3

git-svn-id: https://svn.musicpd.org/mpd/trunk@4507 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 6f695b8d
...@@ -384,12 +384,10 @@ _DeleteAt(TreeIterator * iter) ...@@ -384,12 +384,10 @@ _DeleteAt(TreeIterator * iter)
void * dataToFree = *data; void * dataToFree = *data;
{ {
TreeNode * child = NULL;
// find the least greater than data to fill the whole! // find the least greater than data to fill the whole!
if (node->children[pos+1]) if (node->children[pos+1])
{ {
child = node->children[++pos]; TreeNode * child = node->children[++pos];
while (child->children[0]) while (child->children[0])
{ {
pos = 0; pos = 0;
...@@ -403,7 +401,7 @@ _DeleteAt(TreeIterator * iter) ...@@ -403,7 +401,7 @@ _DeleteAt(TreeIterator * iter)
// or the greatest lesser than data to fill the whole! // or the greatest lesser than data to fill the whole!
else if (node->children[pos]) else if (node->children[pos])
{ {
child = node->children[pos]; TreeNode * child = node->children[pos];
while (child->children[child->dataCount]) while (child->children[child->dataCount])
{ {
pos = child->dataCount; pos = child->dataCount;
...@@ -427,12 +425,12 @@ _DeleteAt(TreeIterator * iter) ...@@ -427,12 +425,12 @@ _DeleteAt(TreeIterator * iter)
// move data nodes over, we're at a leaf node, so we can ignore // move data nodes over, we're at a leaf node, so we can ignore
// children // children
int i = --node->dataCount; int i = data - node->data;;
for (; data != &(node->data[i]); i--) for (; i < node->dataCount-1; i++)
{ {
node->data[i-1] = node->data[i]; node->data[i] = node->data[i+1];
} }
node->data[node->dataCount] = NULL; node->data[--node->dataCount] = NULL;
// merge the nodes from the bottom up which have too few data // merge the nodes from the bottom up which have too few data
while (node->dataCount < (CHILDREN_PER_NODE/2)) while (node->dataCount < (CHILDREN_PER_NODE/2))
......
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