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 --- config.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'config.c') diff --git a/config.c b/config.c index f511dbd..f49baad 100644 --- a/config.c +++ b/config.c @@ -16,6 +16,8 @@ static void eat_whitespace_and_comments(char **pos) { + assert_return(pos && *pos); + while (true) { while (isspace(**pos)) (*pos)++; @@ -31,9 +33,11 @@ eat_whitespace_and_comments(char **pos) static char * get_line(char **pos) { - char *begin = *pos; - char *end; + char *begin, *end; + + assert_return(pos && *pos, NULL); + begin = *pos; while (isspace(*begin)) begin++; @@ -70,8 +74,7 @@ dnslookup(const char *name, uint16_t port, struct cfg_value *rvalue, bool async) bool rv = false; int r; - if (port < 1 || strlen(name) >= sizeof(dns->name)) - goto out; + assert_return(!empty_str(name) && strlen(name) < sizeof(dns->name) && port > 0 && rvalue, false); if (async) { rvalue->type = CFG_VAL_TYPE_ASYNC_ADDRS; @@ -166,8 +169,7 @@ strtosockaddrs(const char *str, struct cfg_value *rvalue, bool async) struct list_head *list; unsigned naddrs = 0; - if (!str || *str == '\0' || !rvalue) - return false; + assert_return(!empty_str(str) && rvalue, false); rvalue->type = CFG_VAL_TYPE_ADDRS; list = &rvalue->saddrs; @@ -320,8 +322,7 @@ config_parse_line(struct cfg *cfg, const char *filename, char **buf, char *line, *tmp, *key; int i; - if (!cfg || !buf || !*buf || !kvmap || !rkey || !rkeyname || !rvalue) - die("%s: invalid parameters", filename); + assert_return(cfg && buf && *buf && kvmap && rkey && rkeyname && rvalue, false); eat_whitespace_and_comments(buf); line = get_line(buf); @@ -470,8 +471,7 @@ config_parse_header(struct cfg *cfg, const char *filename, const char *title, { char *line; - if (!cfg || !title || !buf || !*buf) - return false; + assert_return(cfg && !empty_str(filename) && !empty_str(title) && buf && *buf, false); eat_whitespace_and_comments(buf); -- cgit v1.2.3