Commit ae97bcdf authored by Eric Wong's avatar Eric Wong

sparse / gcc-2.95 / -pedantic fixes

Not everybody has access to the latest and greatest compilers. git-svn-id: https://svn.musicpd.org/mpd/trunk@4595 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent d54df97b
...@@ -415,6 +415,7 @@ static void killFromPidFile(char *cmd, int killOption) ...@@ -415,6 +415,7 @@ static void killFromPidFile(char *cmd, int killOption)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
Options options; Options options;
clock_t start;
closeAllFDs(); closeAllFDs();
...@@ -477,7 +478,7 @@ int main(int argc, char *argv[]) ...@@ -477,7 +478,7 @@ int main(int argc, char *argv[])
freeAllInterfaces(); freeAllInterfaces();
closeAllListenSockets(); closeAllListenSockets();
clock_t start = clock(); start = clock();
closeMp3Directory(); closeMp3Directory();
DEBUG("closeMp3Directory took %f seconds\n", DEBUG("closeMp3Directory took %f seconds\n",
((float)(clock()-start))/CLOCKS_PER_SEC); ((float)(clock()-start))/CLOCKS_PER_SEC);
......
...@@ -58,9 +58,9 @@ char *getTagItemString(int type, char *string) ...@@ -58,9 +58,9 @@ char *getTagItemString(int type, char *string)
else else
{ {
TagTrackerItem *item = malloc(sizeof(TagTrackerItem)); TagTrackerItem *item = malloc(sizeof(TagTrackerItem));
char *key = strdup(string);
item->count = 1; item->count = 1;
item->visited = 0; item->visited = 0;
char * key= strdup(string);
InsertInTree(tagTrees[type], key, item); InsertInTree(tagTrees[type], key, item);
return key; return key;
} }
......
...@@ -57,7 +57,7 @@ struct _Tree ...@@ -57,7 +57,7 @@ struct _Tree
static static
TreeNode * TreeNode *
_MakeNode() _MakeNode(void)
{ {
TreeNode * ret = malloc(sizeof(TreeNode)); TreeNode * ret = malloc(sizeof(TreeNode));
memset(ret, 0, sizeof(TreeNode)); memset(ret, 0, sizeof(TreeNode));
...@@ -147,12 +147,12 @@ static ...@@ -147,12 +147,12 @@ static
TreeNode * TreeNode *
_SplitNode(TreeNode * node) _SplitNode(TreeNode * node)
{ {
assert(node->count == DATA_PER_NODE); TreeNode *newNode = _MakeNode();
TreeNode * newNode = _MakeNode();
int i = DATA_PER_NODE/2; int i = DATA_PER_NODE/2;
int j = 0; int j = 0;
assert(node->count == DATA_PER_NODE);
for (; i < DATA_PER_NODE; i++, j++) for (; i < DATA_PER_NODE; i++, j++)
{ {
newNode->keyData[j] = node->keyData[i]; newNode->keyData[j] = node->keyData[i];
...@@ -179,9 +179,10 @@ _InsertNodeAndData(Tree * tree, ...@@ -179,9 +179,10 @@ _InsertNodeAndData(Tree * tree,
TreeNode * newNode, TreeNode * newNode,
TreeKeyData keyData) TreeKeyData keyData)
{ {
int j = node->count;
assert(node->count < DATA_PER_NODE); assert(node->count < DATA_PER_NODE);
int j = node->count;
for (; j > pos; j--) for (; j > pos; j--)
{ {
node->keyData[j] = node->keyData[j-1]; node->keyData[j] = node->keyData[j-1];
...@@ -212,10 +213,10 @@ _AddDataToSplitNodes(Tree * tree, ...@@ -212,10 +213,10 @@ _AddDataToSplitNodes(Tree * tree,
TreeNode * newNode, TreeNode * newNode,
TreeKeyData keyData) TreeKeyData keyData)
{ {
assert(moreNode->children[0] == NULL);
TreeKeyData retKeyData; TreeKeyData retKeyData;
assert(moreNode->children[0] == NULL);
if (pos <= lessNode->count) if (pos <= lessNode->count)
{ {
_InsertNodeAndData(tree, lessNode, pos, newNode, keyData); _InsertNodeAndData(tree, lessNode, pos, newNode, keyData);
...@@ -233,12 +234,13 @@ _AddDataToSplitNodes(Tree * tree, ...@@ -233,12 +234,13 @@ _AddDataToSplitNodes(Tree * tree,
} }
else else
{ {
int j;
pos -= lessNode->count; pos -= lessNode->count;
retKeyData = moreNode->keyData[0]; retKeyData = moreNode->keyData[0];
assert(!moreNode->children[0]); assert(!moreNode->children[0]);
int j = 0; for (j = 0; j < pos; j++)
for (; j < pos; j++)
{ {
moreNode->keyData[j] = moreNode->keyData[j+1]; moreNode->keyData[j] = moreNode->keyData[j+1];
moreNode->children[j] = moreNode->children[j+1]; moreNode->children[j] = moreNode->children[j+1];
...@@ -270,13 +272,13 @@ _InsertAt(TreeIterator * iter, TreeKeyData keyData) ...@@ -270,13 +272,13 @@ _InsertAt(TreeIterator * iter, TreeKeyData keyData)
while (node != NULL) while (node != NULL)
{ {
// see if there's any NULL data in the current node /* see if there's any NULL data in the current node */
if (node->count == DATA_PER_NODE) if (node->count == DATA_PER_NODE)
{ {
// no open data slots, split this node! /* no open data slots, split this node! */
TreeNode * newNode = _SplitNode(node); TreeNode * newNode = _SplitNode(node);
// insert data in split nodes /* insert data in split nodes */
keyData = _AddDataToSplitNodes(iter->tree, keyData = _AddDataToSplitNodes(iter->tree,
node, node,
newNode, newNode,
...@@ -305,7 +307,7 @@ _InsertAt(TreeIterator * iter, TreeKeyData keyData) ...@@ -305,7 +307,7 @@ _InsertAt(TreeIterator * iter, TreeKeyData keyData)
} }
else else
{ {
// insert the data and newNode /* insert the data and newNode */
_InsertNodeAndData(iter->tree, _InsertNodeAndData(iter->tree,
node, node,
pos, pos,
...@@ -355,9 +357,10 @@ _DeleteAt(TreeIterator * iter) ...@@ -355,9 +357,10 @@ _DeleteAt(TreeIterator * iter)
int pos = iter->which - 1; int pos = iter->which - 1;
TreeKeyData * keyData = &(node->keyData[pos]); TreeKeyData * keyData = &(node->keyData[pos]);
TreeKeyData keyDataToFree = *keyData; TreeKeyData keyDataToFree = *keyData;
int i;
{ {
// 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])
{ {
TreeNode * child = node->children[++pos]; TreeNode * child = node->children[++pos];
...@@ -371,7 +374,7 @@ _DeleteAt(TreeIterator * iter) ...@@ -371,7 +374,7 @@ _DeleteAt(TreeIterator * iter)
keyData = &(child->keyData[0]); keyData = &(child->keyData[0]);
node = child; node = child;
} }
// 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])
{ {
TreeNode * child = node->children[pos]; TreeNode * child = node->children[pos];
...@@ -391,25 +394,25 @@ _DeleteAt(TreeIterator * iter) ...@@ -391,25 +394,25 @@ _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 = keyData - node->keyData;; i = keyData - node->keyData;
for (; i < node->count-1; i++) for (; i < node->count-1; i++)
{ {
node->keyData[i] = node->keyData[i+1]; node->keyData[i] = node->keyData[i+1];
} }
_ClearKeyData(&(node->keyData[--node->count])); _ClearKeyData(&(node->keyData[--node->count]));
// 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->count < (DATA_PER_NODE/2)) while (node->count < (DATA_PER_NODE/2))
{ {
// if we're not the root /* if we're not the root */
if (node->parent) if (node->parent)
{ {
TreeNode ** child = &(node->parent->children[pos]); TreeNode ** child = &(node->parent->children[pos]);
assert(node->parent->children[pos] == node); assert(node->parent->children[pos] == node);
// check siblings for extra data /* check siblings for extra data */
if (pos < node->parent->count && if (pos < node->parent->count &&
(*(child+1))->count > (DATA_PER_NODE/2)) (*(child+1))->count > (DATA_PER_NODE/2))
{ {
...@@ -427,7 +430,7 @@ _DeleteAt(TreeIterator * iter) ...@@ -427,7 +430,7 @@ _DeleteAt(TreeIterator * iter)
} }
node->parent->keyData[pos] = node->parent->keyData[pos] =
(*child)->keyData[0]; (*child)->keyData[0];
int i = 0; i = 0;
for(; i < (*child)->count-1; i++) for(; i < (*child)->count-1; i++)
{ {
(*child)->keyData[i] = (*child)->keyData[i] =
...@@ -453,7 +456,7 @@ _DeleteAt(TreeIterator * iter) ...@@ -453,7 +456,7 @@ _DeleteAt(TreeIterator * iter)
(*(child-1))->count>(DATA_PER_NODE/2)) (*(child-1))->count>(DATA_PER_NODE/2))
{ {
child--; child--;
int i = node->count++; i = node->count++;
for(; i > 0; i--) for(; i > 0; i--)
{ {
node->keyData[i] = node->keyData[i-1]; node->keyData[i] = node->keyData[i-1];
...@@ -484,7 +487,7 @@ _DeleteAt(TreeIterator * iter) ...@@ -484,7 +487,7 @@ _DeleteAt(TreeIterator * iter)
_ClearKeyData( _ClearKeyData(
&((*child)->keyData[(*child)->count])); &((*child)->keyData[(*child)->count]));
} }
// merge with one of our siblings /* merge with one of our siblings */
else else
{ {
if (pos < node->parent->count) if (pos < node->parent->count)
...@@ -511,7 +514,7 @@ _DeleteAt(TreeIterator * iter) ...@@ -511,7 +514,7 @@ _DeleteAt(TreeIterator * iter)
node = *child; node = *child;
} }
int i = pos; i = pos;
for(; i < node->parent->count-1; i++) for(; i < node->parent->count-1; i++)
{ {
node->parent->keyData[i] = node->parent->keyData[i] =
...@@ -532,7 +535,7 @@ _DeleteAt(TreeIterator * iter) ...@@ -532,7 +535,7 @@ _DeleteAt(TreeIterator * iter)
pos = node->parentPos; pos = node->parentPos;
} }
} }
// this is a root node /* this is a root node */
else else
{ {
if (node->count == 0) if (node->count == 0)
...@@ -654,8 +657,9 @@ GetTreeKeyData(TreeIterator * iter) ...@@ -654,8 +657,9 @@ GetTreeKeyData(TreeIterator * iter)
int int
InsertInTree(Tree * tree, void * key, void * data) InsertInTree(Tree * tree, void * key, void * data)
{ {
TreeKeyData keyData = {key, data}; TreeKeyData keyData;
TreeIterator iter; TreeIterator iter;
_SetIteratorToRoot(tree, &iter); _SetIteratorToRoot(tree, &iter);
if (_Find(&iter, key)) if (_Find(&iter, key))
...@@ -663,6 +667,8 @@ InsertInTree(Tree * tree, void * key, void * data) ...@@ -663,6 +667,8 @@ InsertInTree(Tree * tree, void * key, void * data)
return 0; return 0;
} }
keyData.key = key;
keyData.data = data;
_InsertAt(&iter, keyData); _InsertAt(&iter, keyData);
tree->size++; tree->size++;
......
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