]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Improve readability of ternary expression checking for empty string
authorBrad King <brad.king@kitware.com>
Wed, 21 Oct 2015 15:59:45 +0000 (11:59 -0400)
committerBrad King <brad.king@kitware.com>
Mon, 26 Oct 2015 14:17:49 +0000 (10:17 -0400)
In expressions of the form

    m != NULL && m[0] == '\0' ? NULL : m

the goal is to get a `NULL` pointer if `m` is either `NULL` or an empty
string.  This is not clear because in the `m == NULL` case we use the
`m` side to get `NULL` instead of an explicit `NULL`.  Clarify the
intent by using the form

    (m != NULL && m[0] != '\0') ? m : NULL;

instead.

libarchive/archive_options.c

index 8af623931f016ae0fbe258e38fe7896748703404..dbf3e80e90243fe710593a87f98629844520659d 100644 (file)
@@ -42,9 +42,9 @@ _archive_set_option(struct archive *a,
 
        archive_check_magic(a, magic, ARCHIVE_STATE_NEW, fn);
 
-       mp = m != NULL && m[0] == '\0' ? NULL : m;
-       op = o != NULL && o[0] == '\0' ? NULL : o;
-       vp = v != NULL && v[0] == '\0' ? NULL : v;
+       mp = (m != NULL && m[0] != '\0') ? m : NULL;
+       op = (o != NULL && o[0] != '\0') ? o : NULL;
+       vp = (v != NULL && v[0] != '\0') ? v : NULL;
 
        if (op == NULL && vp == NULL)
                return (ARCHIVE_OK);