From 204e8f8b2282a476d5f2b97abee0d81c119dd6bf Mon Sep 17 00:00:00 2001 From: Nakidai Date: Tue, 10 Feb 2026 21:25:47 +0300 Subject: Fix channel_exit()ing user_remove() When user user_remove() is called, that user quits all of the channels it was belonging to. But since channel_exit() mutates chanels array, it is incorrect to 1) compare with channels_c 2) access channels[i]. As a fix, 1) channels_c is not being compared throughout the loop but is assigned to i once, and then i decrements 2) channels is being accessed only as channels[0] --- user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'user.c') diff --git a/user.c b/user.c index 5d9bc15..0932b0e 100644 --- a/user.c +++ b/user.c @@ -91,8 +91,8 @@ user_remove(size_t pid) struct Peer *last; size_t i, j; - for (i = 0; i < peers[pid].channels_c; ++i) - channel_exit(peers[pid].channels[i], &peers[pid]); + for (i = peers[pid].channels_c; i; --i) + channel_exit(peers[pid].channels[0], &peers[pid]); last = &peers[peers_c-1]; for (i = 0; i < last->channels_c; ++i) -- cgit 1.4.1