From 9380231e0ef0398ffb2ad2a6d455ded9fd40e73f Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Thu, 24 Oct 2019 18:18:32 -0400 Subject: Zero entire Client struct Does zeroing that extra 4K really matter? I'd rather not have uninitialized reads. --- client.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index eaa8555..4bb1f54 100644 --- a/client.c +++ b/client.c @@ -46,15 +46,10 @@ struct Client { }; struct Client *clientAlloc(struct tls *tls) { - struct Client *client = malloc(sizeof(*client)); - if (!client) err(EX_OSERR, "malloc"); - - client->error = false; + struct Client *client = calloc(1, sizeof(*client)); + if (!client) err(EX_OSERR, "calloc"); client->tls = tls; client->need = NeedNick | NeedUser | (clientPass ? NeedPass : 0); - client->serverTime = false; - client->len = 0; - return client; } @@ -185,12 +180,7 @@ static const struct { static void clientParse(struct Client *client, char *line) { struct Message msg = parse(line); - if (!msg.cmd) { - // FIXME: Identify client in message. - warnx("no command"); - client->error = true; - return; - } + if (!msg.cmd) return; for (size_t i = 0; i < ARRAY_LEN(Handlers); ++i) { if (strcmp(msg.cmd, Handlers[i].cmd)) continue; Handlers[i].fn(client, msg); -- cgit 1.4.1