From 72afc6f0e8f3cec187969354d63ad18574102718 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 21 Oct 2015 11:59:45 -0400 Subject: [PATCH] Improve readability of ternary expression checking for empty string 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 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libarchive/archive_options.c b/libarchive/archive_options.c index 8af623931..dbf3e80e9 100644 --- a/libarchive/archive_options.c +++ b/libarchive/archive_options.c @@ -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); -- 2.47.2