From 003159e92bb4526845a8a1a1a4627824e939cd4b Mon Sep 17 00:00:00 2001 From: David Härdeman Date: Sun, 21 Jun 2020 11:43:49 +0200 Subject: Convert three more files to use assert --- cfgdir.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'cfgdir.c') diff --git a/cfgdir.c b/cfgdir.c index 923926b..54d6450 100644 --- a/cfgdir.c +++ b/cfgdir.c @@ -27,10 +27,7 @@ scfg_dns_cb(struct dns_async *dns, bool (*server_cb)(struct cfg *, struct server struct addrinfo *results = NULL, *ai; int r; - if (!dns || !dns->priv || !server_cb) { - error("invalid arguments"); - return; - } + assert_return(dns && dns->priv && server_cb); server = dns->priv; cfg = server->cfg; @@ -93,18 +90,24 @@ out: static void scfg_local_dns_cb(struct dns_async *dns) { + assert_return(dns); + scfg_dns_cb(dns, server_add_local); } static void scfg_remote_dns_cb(struct dns_async *dns) { + assert_return(dns); + scfg_dns_cb(dns, server_add_remote); } static void scfg_rcon_dns_cb(struct dns_async *dns) { + assert_return(dns); + scfg_dns_cb(dns, server_add_rcon); } @@ -193,6 +196,8 @@ handle_dns(struct cfg *cfg, struct server *server, const char *type, struct saddr *saddr, *tmp; struct dns_async *dns; + assert_return(cfg && server && type && value && async_cb && sync_cb, false); + switch (value->type) { case CFG_VAL_TYPE_ADDRS: debug(DBG_DNS, "%s: got immediate addrs", type); @@ -222,7 +227,11 @@ handle_dns(struct cfg *cfg, struct server *server, const char *type, static void scfg_parse(struct cfg *cfg, struct server *server) { - char *pos = &server->tbuf.buf[0]; + char *pos; + + assert_return(cfg && server); + + pos = server->tbuf.buf; if (!config_parse_header(cfg, server->name, "server", &pos)) return; @@ -341,6 +350,7 @@ scfg_read_cb(struct cfg *cfg, struct uring_task *task, int res) { struct server *server = container_of(task, struct server, task); + assert_return(cfg && task); assert_task_alive(DBG_CFG, task); if (res <= 0) { @@ -360,6 +370,7 @@ scfg_open_cb(struct cfg *cfg, struct uring_task *task, int res) { struct server *server = container_of(task, struct server, task); + assert_return(cfg && task); assert_task_alive(DBG_CFG, task); if (res < 0) { @@ -401,11 +412,9 @@ inotify_free(struct uring_task *task) struct inotify_ev *iev = container_of(task, struct inotify_ev, task); struct cfg *cfg = container_of(task->parent, struct cfg, task); - debug(DBG_CFG, "called"); - - if (!iev || !cfg) - die("iev or cfg is NULL!?"); + assert_return(task && iev && cfg); + debug(DBG_CFG, "called"); xfree(iev); cfg->iev = NULL; } @@ -413,6 +422,8 @@ inotify_free(struct uring_task *task) static void inotify_event_dump(const struct inotify_event *event) { + assert_return(event); + debug(DBG_CFG, "inotify event:"); debug(DBG_CFG, " * WD : %i", event->wd); debug(DBG_CFG, " * Cookie : %" PRIu32, event->cookie); @@ -459,6 +470,7 @@ inotify_cb(struct cfg *cfg, struct uring_task *task, int res) char *ptr; struct server *server; + assert_return(cfg && task); assert_task_alive(DBG_CFG, task); if (res <= 0) { @@ -499,16 +511,15 @@ inotify_cb(struct cfg *cfg, struct uring_task *task, int res) void cfgdir_refdump(struct inotify_ev *iev) { + assert_return(iev); + uring_task_refdump(&iev->task); } void cfgdir_delete(struct cfg *cfg) { - if (!cfg->iev) { - error("missing arguments"); - return; - } + assert_return(cfg && cfg->iev); debug(DBG_CFG, "closing fd %i", cfg->iev->task.fd); uring_task_destroy(cfg, &cfg->iev->task); @@ -525,6 +536,8 @@ cfgdir_init(struct cfg *cfg) struct dirent *dent; struct server *server; + assert_return(cfg); + iev = zmalloc(sizeof(*iev)); if (!iev) die("malloc: %m"); -- cgit v1.2.3