nio

a simple irc client
git clone git@git.kloet.net/nio.git
Download | Log | Files | Refs | README

commit b4cb5ca9f3f17b5b179e14f9cec4a60eae62b393
parent d0edb34808b4c7608ab253d38e707e97e9d32569
Author: Andrew Kloet <andrew@kloet.net>
Date:   Sun, 29 Mar 2026 00:11:27 -0400

add more guards to chdel

Diffstat:
Mnio.c | 14++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/nio.c b/nio.c @@ -376,14 +376,13 @@ chadd(const char *name, int joined) static int chdel(char *name) { - int n; - - if (!(n = chfind(name))) - return 0; - nch--; + int n = chfind(name); if (n <= 0) return 0; free(chl[n].buf); - memmove(&chl[n], &chl[n + 1], (nch - n) * sizeof(struct Chan)); - ch = nch - 1; + nch--; + if (n < nch) /* Shift the channel buffers down. */ + memmove(&chl[n], &chl[n + 1], (nch - n) * sizeof(struct Chan)); + if (ch >= n) /* Decrement the selected channel. */ + ch = (ch > 0) ? ch - 1 : 0; tdrawbar(); return 1; } @@ -961,7 +960,6 @@ main(int argc, char *argv[]) struct Chan *c; fd_set rfs, wfs; int ret; - if (winchg) tresize(); FD_ZERO(&wfs);