hirc

IRC client
Log | Files | Refs

commit 19ae3eb85b53e4557a10b2f43b7f49e33f7ac494
parent ac00d91b91e9a1b8e6b550a576d5691806b1c6fe
Author: hhvn <dev@hhvn.uk>
Date:   Sun,  3 Apr 2022 10:53:20 +0100

Fix remove functions for linked lists

Diffstat:
Msrc/chan.c | 11++++-------
Msrc/nick.c | 12++++--------
Msrc/serv.c | 11++++-------
3 files changed, 12 insertions(+), 22 deletions(-)

diff --git a/src/chan.c b/src/chan.c @@ -144,15 +144,12 @@ chan_remove(struct Channel **head, char *name) { if ((p = chan_get(head, name, -1)) == NULL) return 0; - if (p->prev == NULL) { + if (*head == p) *head = p->next; - chan_free(p); - return 1; - } - - p->prev->next = p->next; - if (p->next != NULL) + if (p->next) p->next->prev = p->prev; + if (p->prev) + p->prev->next = p->next; chan_free(p); return 1; } diff --git a/src/nick.c b/src/nick.c @@ -218,17 +218,13 @@ nick_remove(struct Nick **head, char *nick) { if ((p = nick_get(head, nick)) == NULL) return 0; - if (p->prev == NULL) { + if (*head == p) *head = p->next; - nick_free(p); - return 1; - } - - p->prev->next = p->next; - if (p->next != NULL) + if (p->next) p->next->prev = p->prev; + if (p->prev) + p->prev->next = p->next; nick_free(p); - return 1; } diff --git a/src/serv.c b/src/serv.c @@ -162,15 +162,12 @@ serv_remove(struct Server **head, char *name) { if ((p = serv_get(head, name)) == NULL) return 0; - if (p->prev == NULL) { + if (*head == p) *head = p->next; - serv_free(p); - return 1; - } - - p->prev->next = p->next; - if (p->next != NULL) + if (p->next) p->next->prev = p->prev; + if (p->prev) + p->prev->next = p->next; serv_free(p); return 1; }