nbd-server: prefer assertions over if-then-exits
authorTuomas Räsänen <tuomasjjrasanen@opinsys.fi>
Mon, 11 Mar 2013 13:58:05 +0000 (15:58 +0200)
committerWouter Verhelst <w@uter.be>
Tue, 12 Mar 2013 08:18:17 +0000 (09:18 +0100)
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@tjjr.fi>
Signed-off-by: Wouter Verhelst <w@uter.be>
nbd-server.c

index b8fff4b..b81aa19 100644 (file)
@@ -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);