chiark / gitweb /
tree-wide: drop a few == NULL and != NULL comparison
authorLennart Poettering <lennart@poettering.net>
Fri, 8 Dec 2017 19:52:38 +0000 (20:52 +0100)
committerSven Eden <yamakuzure@gmx.net>
Fri, 8 Dec 2017 19:52:38 +0000 (20:52 +0100)
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)

coccinelle/equals-null.cocci [new file with mode: 0644]
src/basic/fileio.c
src/basic/path-util.c
src/basic/time-util.c

diff --git a/coccinelle/equals-null.cocci b/coccinelle/equals-null.cocci
new file mode 100644 (file)
index 0000000..957d828
--- /dev/null
@@ -0,0 +1,14 @@
+@@
+expression e;
+statement s;
+@@
+- if (e == NULL)
++ if (!e)
+s
+@@
+expression e;
+statement s;
+@@
+- if (e != NULL)
++ if (e)
+s
index 53ada062f0fcb888931ae66d4d66682fd36e331b..3c2f9742ea73387c55b82c0b7566b7740f4fd557 100644 (file)
@@ -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);
index 83751716a48a592f95982490a32cfa3729164d6b..2a766154bf0ee1884383540e507652e7e602be8c 100644 (file)
@@ -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) {
index 718d2b31b2a5f941f308581f3ad7a189c7f82b17..e9d17a8cc78f31ab0a58d9f3e34cc3f71d441b81 100644 (file)
@@ -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);