From 896e454c4076c0d9cbe9c7fe20ff2258536f4f2f Mon Sep 17 00:00:00 2001 From: Saturneric Date: Wed, 13 Jun 2018 16:15:25 +0800 Subject: [PATCH] debug --- list/list.c | Bin 20250 -> 20432 bytes list/list_expand.c | 48 ++++++++++++++++++++++++++------------------- test.c | 3 ++- tree/tree.c | 2 +- 4 files changed, 31 insertions(+), 22 deletions(-) diff --git a/list/list.c b/list/list.c index 5807c185967f5e568911ee5e02c9692e55d3834a..005cfa229c63b3a436d4f8b9f8cfb1de9a9d8e3b 100644 GIT binary patch delta 55 zcmbO=kMY8M#tnKJllNF~O!iQho17rcF*#3NX7WERi^)84DwDVA$xW8fmIJbRHtT4s LF>dbB>{A5*BVH0K delta 23 fcmcaGpK;ba#tnKJn^$SaF;3=D6WAQ2Ri_F7Zy^Xi diff --git a/list/list_expand.c b/list/list_expand.c index 3a756bc..32c20d7 100644 --- a/list/list_expand.c +++ b/list/list_expand.c @@ -140,19 +140,19 @@ void printNodeInfo(Node *p_node, int priority) { printf("NEXT->%p / LAST->%p / MALLOC:%d\n", p_node->next, p_node->last, p_node->if_malloc); if (!strcmp(p_node->type, "int")) { for (int i = 0; i < priority + 1; i++) printf(" "); - printf("VALUE(Int):%d\n", *(int *)(p_node->value)); + printf("VALUE(int):%d\n", *(int *)(p_node->value)); } else if (!strcmp(p_node->type, "double")) { for (int i = 0; i < priority + 1; i++) printf(" "); - printf("VALUE(Double):%a\n", *(double *)(p_node->value)); + printf("VALUE(double):%a\n", *(double *)(p_node->value)); } else if (!strcmp(p_node->type, "string")) { for (int i = 0; i < priority + 1; i++) printf(" "); - printf("VALUE(String):%s\n", (char *)(p_node->value)); + printf("VALUE(string):%s\n", (char *)(p_node->value)); } else if (!strcmp(p_node->type, "pointer")) { for (int i = 0; i < priority + 1; i++) printf(" "); - printf("VALUE(Pointer):%s\n", (char *)(p_node->value)); + printf("VALUE(pointer):%s\n", (char *)(p_node->value)); } else if (!strcmp(p_node->type, "list")) { for (int i = 0; i < priority + 1; i++) printf(" "); @@ -166,23 +166,31 @@ void printNodeInfo(Node *p_node, int priority) { void printNode(Node *p_node) { printf("#NODE(location:%p, id:%llu){\n", p_node, p_node->id); printf(" "); - printf("NEXT->%p / LAST->%p / MALLOC:%d\n", p_node->next, p_node->last, p_node->if_malloc); - printf(" "); - if (!strcmp(p_node->type, "int")) { - printf("%d", *(int *)(p_node->value)); - } - else if (!strcmp(p_node->type, "double")) { - printf("%a\n", *(double *)(p_node->value)); - } - else if (!strcmp(p_node->type, "string")) { - printf("%s\n", (char *)(p_node->value)); - } - else if (!strcmp(p_node->type, "pointer")) { - printf("%s\n", (char *)(p_node->value)); - } - else if (!strcmp(p_node->type, "list")) { - printList((List *)p_node->value); + printf("NEXT->%p / LAST->%p\n", p_node->next, p_node->last, p_node->if_malloc); + for (int i = 0; i < 1; i++) printf(" "); + printf("ifMalloc: "); + if (p_node->if_malloc) { + printf("YES\n"); + for (int i = 0; i < 1; i++) printf(" "); + printf("Value(type: %s): ", p_node->type); + if (!strcmp(p_node->type, "int")) { + printf("%d", *(int *)(p_node->value)); + } + else if (!strcmp(p_node->type, "double")) { + printf("%a\n", *(double *)(p_node->value)); + } + else if (!strcmp(p_node->type, "string")) { + printf("%s\n", (char *)(p_node->value)); + } + else if (!strcmp(p_node->type, "pointer")) { + printf("%s\n", (char *)(p_node->value)); + } + else if (!strcmp(p_node->type, "list")) { + printList((List *)p_node->value); + } } + else printf("NO\n"); + printf("}\n"); } diff --git a/test.c b/test.c index 14423f9..89b0134 100644 --- a/test.c +++ b/test.c @@ -47,8 +47,9 @@ int tree(void) { addChildInRight(cl_tnode, tnodeWithInt(5)); addChildInRight(cr_tnode, tnodeWithInt(6)); addChildInRight(cr_tnode, tnodeWithInt(7)); + + removeChildByIndex(cr_tnode, 1); printTNodeWithFamily(t_tnode, 0); - //removeChildByIndex(t_tnode, 0); releaseAllForTree(); return 0; } diff --git a/tree/tree.c b/tree/tree.c index 0d42a14..9c0c123 100644 --- a/tree/tree.c +++ b/tree/tree.c @@ -250,7 +250,7 @@ TNode *getChildByIndex(TNode *p_tnode, unsigned long long index) { List *p_home = p_tnode->home; Node *p_node = p_home->head; int m_index = 0; - if (index < p_tnode->child_num - 1) + if (index < p_tnode->child_num) { while (p_node != NULL && m_index < index) { m_index++;