From f4ba2638c774e0dedf4cf2e965218b3600c1e1ba Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Wed, 23 Oct 2019 03:12:45 -0400 Subject: Set an initial loop cap --- bounce.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bounce.c b/bounce.c index 3e30d0c..e91ed7f 100644 --- a/bounce.c +++ b/bounce.c @@ -35,7 +35,7 @@ static struct { static void loopAdd(int fd, struct Client *client) { if (loop.len == loop.cap) { - loop.cap *= 2; + loop.cap = (loop.cap ? loop.cap * 2 : 4); loop.fds = realloc(loop.fds, sizeof(struct pollfd) * loop.cap); loop.clients = realloc(loop.clients, sizeof(struct Client *) * loop.cap); if (!loop.fds || !loop.clients) err(EX_OSERR, "realloc"); @@ -48,9 +48,9 @@ static void loopAdd(int fd, struct Client *client) { } static void loopRemove(size_t i) { - loop.fds[i] = loop.fds[loop.len - 1]; - loop.clients[i] = loop.clients[loop.len - 1]; loop.len--; + loop.fds[i] = loop.fds[loop.len]; + loop.clients[i] = loop.clients[loop.len]; } static char *censor(char *arg) { -- cgit 1.4.1