fixed possible segfault in remove_node

This commit is contained in:
Václav Šmejkal 2023-02-02 16:52:42 +01:00
parent 77b5d5acae
commit 790eada639
Signed by: ENGO150
GPG Key ID: 4A57E86482968843

View File

@ -44,10 +44,6 @@ void push_to_list(void *pointer)
void remove_node(node_t *node) void remove_node(node_t *node)
{ {
/*
This whole function assumes the node is in the list, so if you use this without pushing it, bad things will happen :)
*/
node_t *buffer_1 = head; node_t *buffer_1 = head;
node_t *buffer_2; node_t *buffer_2;
@ -58,6 +54,8 @@ void remove_node(node_t *node)
buffer_1 = buffer_1 -> next; buffer_1 = buffer_1 -> next;
} }
if (node != buffer_1) return; //node WASN'T FOUND
if (buffer_1 == head) //node WAS THE FIRST NODE IN THE LIST if (buffer_1 == head) //node WAS THE FIRST NODE IN THE LIST
{ {
//UNLINK //UNLINK