aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-11-15 18:35:23 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-11-15 18:35:23 +0000
commitf3e8d59d5c584f5925a8b23919aaa5b5c954cf85 (patch)
tree8561cfc8a3317f4c2beb7d641ebd2c495149e2f4
parentc3b76c4171c1737a1d0066c8ec38062d7ba327e0 (diff)
downloadmpd-f3e8d59d5c584f5925a8b23919aaa5b5c954cf85.tar.gz
mpd-f3e8d59d5c584f5925a8b23919aaa5b5c954cf85.tar.xz
mpd-f3e8d59d5c584f5925a8b23919aaa5b5c954cf85.zip
use realloc for makeListNodesArray
git-svn-id: https://svn.musicpd.org/mpd/trunk@2676 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/list.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/src/list.c b/src/list.c
index 45b19a93a..a777562d4 100644
--- a/src/list.c
+++ b/src/list.c
@@ -31,7 +31,8 @@ void makeListNodesArray(List * list) {
if(!list->numberOfNodes) return;
- list->nodesArray = malloc(sizeof(ListNode *)*list->numberOfNodes);
+ list->nodesArray = realloc(list->nodesArray,
+ sizeof(ListNode *)*list->numberOfNodes);
for(i=0;i<list->numberOfNodes;i++) {
list->nodesArray[i] = node;
@@ -71,41 +72,40 @@ ListNode * insertInListBeforeNode(List * list, ListNode * beforeNode, char *
node = malloc(sizeof(ListNode));
assert(node!=NULL);
- if(beforeNode==NULL) node = insertInList(list, key, data);
- else {
- node->nextNode = beforeNode;
- if(beforeNode==list->firstNode) {
- if(list->firstNode==NULL) {
- assert(list->lastNode==NULL);
- list->lastNode = node;
- }
- else {
- assert(list->lastNode!=NULL);
- assert(list->lastNode->nextNode==NULL);
- list->firstNode->prevNode = node;
- }
- node->prevNode = NULL;
- list->firstNode = node;
+ node->nextNode = beforeNode;
+ if(beforeNode==list->firstNode) {
+ if(list->firstNode==NULL) {
+ assert(list->lastNode==NULL);
+ list->lastNode = node;
}
else {
+ assert(list->lastNode!=NULL);
+ assert(list->lastNode->nextNode==NULL);
+ list->firstNode->prevNode = node;
+ }
+ node->prevNode = NULL;
+ list->firstNode = node;
+ }
+ else {
+ if(beforeNode) {
node->prevNode = beforeNode->prevNode;
- if(node->prevNode) {
- node->prevNode->nextNode = node;
- }
beforeNode->prevNode = node;
}
+ else {
+ node->prevNode = list->lastNode;
+ list->lastNode = node;
+ }
+ node->prevNode->nextNode = node;
+ }
- if(list->strdupKeys) node->key = strdup(key);
- else node->key = key;
+ if(list->strdupKeys) node->key = strdup(key);
+ else node->key = key;
- assert(node->key!=NULL);
+ node->data = data;
- node->data = data;
-
- list->numberOfNodes++;
- }
+ list->numberOfNodes++;
- freeListNodesArray(list);
+ /*freeListNodesArray(list);*/
if(list->sorted) makeListNodesArray(list);
return node;