diff options
| author | David Härdeman <david@hardeman.nu> | 2020-06-21 11:43:49 +0200 | 
|---|---|---|
| committer | David Härdeman <david@hardeman.nu> | 2020-06-21 11:43:49 +0200 | 
| commit | 003159e92bb4526845a8a1a1a4627824e939cd4b (patch) | |
| tree | 8146d8e56172d8de28dd43a0f02355bee585c594 /announce.c | |
| parent | ae48dc3b3caeef7eaa4a079b11cdda988d9c1f0d (diff) | |
Convert three more files to use assert
Diffstat (limited to 'announce.c')
| -rw-r--r-- | announce.c | 34 | 
1 files changed, 20 insertions, 14 deletions
@@ -21,25 +21,22 @@ mcast_free(struct uring_task *task)  {  	struct announce *aev = container_of(task, struct announce, mcast_task); +	assert_return(task);  	debug(DBG_ANN, "task %p, aev %p", task, aev);  }  static void  mcast_sent(struct cfg *cfg, struct uring_task *task, int res)  { -	struct server *server; +	struct server *server = container_of(task->tbuf, struct server, mcast_buf); + +	assert_return(task && task->tbuf);  	if (res < 0)  		error("failure %i", res);  	else  		debug(DBG_ANN, "result %i", res); -	if (!task || !task->tbuf) { -		error("task or task->tbuf not set"); -		return; -	} - -	server = container_of(task->tbuf, struct server, mcast_buf);  	uring_task_put(cfg, &server->task);  } @@ -48,7 +45,10 @@ mcast_send(struct cfg *cfg, struct announce *aev, struct server *server)  {  	int len; -	if (!server || !server->pretty_name || server->announce_port < 1) +	assert_return(cfg && aev && server); + +	/* FIXME: should these be assert:ed as well? */ +	if (!server->pretty_name || server->announce_port < 1)  		return;  	len = snprintf(server->mcast_buf.buf, sizeof(server->mcast_buf.buf), @@ -71,6 +71,8 @@ mcast_send_all(struct cfg *cfg, struct announce *aev)  {  	struct server *server; +	assert_return(cfg && aev); +  	list_for_each_entry(server, &cfg->servers, list) {  		verbose("Announcing server: %s", server->name);  		mcast_send(cfg, aev, server); @@ -82,6 +84,7 @@ announce_cb(struct cfg *cfg, struct uring_task *task, int res)  {  	struct announce *aev = container_of(task, struct announce, task); +	assert_return(cfg && task);  	assert_task_alive(DBG_ANN, task);  	if (res != sizeof(aev->value)) { @@ -99,6 +102,7 @@ announce_free(struct uring_task *task)  {  	struct announce *aev = container_of(task, struct announce, task); +	assert_return(task);  	debug(DBG_ANN, "task %p, aev 0x%p", task, aev);  	xfree(aev);  } @@ -106,8 +110,7 @@ announce_free(struct uring_task *task)  void  announce_refdump(struct announce *aev)  { -	if (!aev) -		return; +	assert_return(aev);  	uring_task_refdump(&aev->task);  	uring_task_refdump(&aev->mcast_task); @@ -116,10 +119,7 @@ announce_refdump(struct announce *aev)  void  announce_delete(struct cfg *cfg)  { -	if (!cfg->aev) { -		error("missing parameters"); -		return; -	} +	assert_return(cfg && cfg->aev);  	debug(DBG_ANN, "closing fd %i", cfg->aev->task.fd);  	uring_task_destroy(cfg, &cfg->aev->mcast_task); @@ -141,6 +141,8 @@ announce_stop(struct announce *aev)  		}  	}; +	assert_return(aev); +  	if (timerfd_settime(aev->task.fd, 0, &tspec, NULL) != 0)  		error("timerfd_settime: %m");  } @@ -159,6 +161,8 @@ announce_start(struct announce *aev)  		}  	}; +	assert_return(aev); +  	if (timerfd_settime(aev->task.fd, 0, &tspec, NULL) != 0)  		error("timerfd_settime: %m");  } @@ -170,6 +174,8 @@ announce_init(struct cfg *cfg)  	int afd;  	int sfd; +	assert_return(cfg); +  	aev = zmalloc(sizeof(*aev));  	if (!aev)  		die("malloc: %m");  | 
