提交 64e59175 authored 作者: zhoush's avatar zhoush

优化: find_node 新增内存检查

上级 83a2236d
流水线 #3142 已失败 于阶段
...@@ -25,10 +25,8 @@ AWList *AWList_init(AWList *list) ...@@ -25,10 +25,8 @@ AWList *AWList_init(AWList *list)
void AWList_destroy(AWList *list) void AWList_destroy(AWList *list)
{ {
if (!list) { if (!list)
return; return;
}
AWList_clear(list); AWList_clear(list);
free(list->head); free(list->head);
...@@ -44,6 +42,7 @@ void AWList_clear(AWList *list) ...@@ -44,6 +42,7 @@ void AWList_clear(AWList *list)
} }
for (; list->tail != list->head; AWList_delete_node(list, list->tail)) for (; list->tail != list->head; AWList_delete_node(list, list->tail))
; ;
list->iter = list->head;
} }
AWNode *AWNode_init(void *data, void (*delete_func)(void *)) AWNode *AWNode_init(void *data, void (*delete_func)(void *))
...@@ -124,6 +123,9 @@ AWNode *AWList_find_node(AWList *list, void *data, ...@@ -124,6 +123,9 @@ AWNode *AWList_find_node(AWList *list, void *data,
AWNode *node; AWNode *node;
AWList_for_each(node, list) AWList_for_each(node, list)
{ {
if (!node || !data) {
return NULL;
}
if (cmp_callback(node->data, data) == 0) if (cmp_callback(node->data, data) == 0)
return node; return node;
} }
...@@ -136,12 +138,10 @@ AWNode *AWList_iterator(AWList *list) ...@@ -136,12 +138,10 @@ AWNode *AWList_iterator(AWList *list)
if (!list || list->iter == list->tail->next) if (!list || list->iter == list->tail->next)
return NULL; return NULL;
if (list->iter == list->head) { if (list->iter == list->head)
list->iter = list->head->next; list->iter = list->head->next;
}
AWNode *iter = list->iter; AWNode *iter = list->iter;
if (list->iter) { if (list->iter) {
list->iter = list->iter->next; list->iter = list->iter->next;
} }
......
...@@ -105,7 +105,8 @@ void AWList_add_tail(AWList *list, void *data, void (*delete_func)(void *)); ...@@ -105,7 +105,8 @@ void AWList_add_tail(AWList *list, void *data, void (*delete_func)(void *));
* *
* @param list pointer of list * @param list pointer of list
* @param data key data to find * @param data key data to find
* @param cmp_callback callback to use data * @param cmp_callback callback to use data,
* 0: node->data is equal to the data to find
* *
* @return the pointer of the node if exists, NULL if not found * @return the pointer of the node if exists, NULL if not found
*/ */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论