[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Nbd] [PATCH 1/1] nbd-server: prefer assertions over if-then-exits



Assertions imply programming invariants which must be fulfilled,
otherwise there is a programming error.

Regarding this commit, it's a programming error to pass NULL to
append_serve(). And now it's explicitly stated with the assert(3)
statement.

If-then-exit -constructs could be interpreted as a valid and
semantically meaningful code: "it's a feature of append_serve() to
exit the process if NULL is passed", which does not make any sense. On
the other hand, assert(s != NULL) makes it very clear that NULL must
not be passed, or the contract will be terminated along with the
process.

This commit is part of the desensitization treatment for author's
assertion allergy.

Signed-off-by: Tuomas Räsänen <tuomasjjrasanen@...1261...>
---
 nbd-server.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/nbd-server.c b/nbd-server.c
index 27c4600..0c5320a 100644
--- a/nbd-server.c
+++ b/nbd-server.c
@@ -710,8 +710,7 @@ int append_serve(const SERVER *const s, GArray *const a) {
 	int e;
 	int ret;
 
-	if(!s)
-		err("Invalid parsing server");
+	assert(s != NULL);
 
 	port = g_strdup_printf("%d", s->port);
 
-- 
1.7.10.4




Reply to: