From: Lennart Poettering Date: Fri, 8 Dec 2017 19:52:38 +0000 (+0100) Subject: tree-wide: drop a few == NULL and != NULL comparison X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=b3826e3b2bd8b5b8eb5365ff084fdc701932f9da;p=elogind.git tree-wide: drop a few == NULL and != NULL comparison Our CODING_STYLE suggests not comparing with NULL, but relying on C's downgrade-to-bool feature for that. Fix up some code to match these guidelines. (This is not comprehensive, the coccinelle output for this is unfortunately kinda borked) --- diff --git a/coccinelle/equals-null.cocci b/coccinelle/equals-null.cocci new file mode 100644 index 000000000..957d828a8 --- /dev/null +++ b/coccinelle/equals-null.cocci @@ -0,0 +1,14 @@ +@@ +expression e; +statement s; +@@ +- if (e == NULL) ++ if (!e) +s +@@ +expression e; +statement s; +@@ +- if (e != NULL) ++ if (e) +s diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 53ada062f..3c2f9742e 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -139,7 +139,7 @@ int write_string_file_ts( return r; } else - assert(ts == NULL); + assert(!ts); if (flags & WRITE_STRING_FILE_CREATE) { f = fopen(fn, "we"); @@ -1196,7 +1196,7 @@ int tempfn_xxxxxx(const char *p, const char *extra, char **ret) { if (!filename_is_valid(fn)) return -EINVAL; - if (extra == NULL) + if (!extra) extra = ""; t = new(char, strlen(p) + 2 + strlen(extra) + 6 + 1); diff --git a/src/basic/path-util.c b/src/basic/path-util.c index 83751716a..2a766154b 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -542,7 +542,7 @@ bool paths_check_timestamp(const char* const* paths, usec_t *timestamp, bool upd assert(timestamp); - if (paths == NULL) + if (!paths) return false; STRV_FOREACH(i, paths) { diff --git a/src/basic/time-util.c b/src/basic/time-util.c index 718d2b31b..e9d17a8cc 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -905,7 +905,7 @@ int parse_timestamp(const char *t, usec_t *usec) { if (last_space != NULL && timezone_is_valid(last_space + 1)) tz = last_space + 1; - if (tz == NULL || endswith_no_case(t, " UTC")) + if (!tz || endswith_no_case(t, " UTC")) return parse_timestamp_impl(t, usec, false); shared = mmap(NULL, sizeof *shared, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0);