diff options
-rw-r--r-- | coccinelle/equals-null.cocci | 14 | ||||
-rw-r--r-- | src/analyze/analyze-verify.c | 2 | ||||
-rw-r--r-- | src/analyze/analyze.c | 8 | ||||
-rw-r--r-- | src/basic/clock-util.c | 2 | ||||
-rw-r--r-- | src/basic/device-nodes.c | 2 | ||||
-rw-r--r-- | src/basic/ether-addr-util.c | 4 | ||||
-rw-r--r-- | src/basic/fileio.c | 4 | ||||
-rw-r--r-- | src/basic/journal-importer.c | 6 | ||||
-rw-r--r-- | src/basic/path-util.c | 2 | ||||
-rw-r--r-- | src/basic/time-util.c | 2 | ||||
-rw-r--r-- | src/boot/efi/measure.c | 4 | ||||
-rw-r--r-- | src/core/execute.c | 2 | ||||
-rw-r--r-- | src/core/main.c | 2 | ||||
-rw-r--r-- | src/coredump/coredump.c | 2 | ||||
-rw-r--r-- | src/vconsole/vconsole-setup.c | 4 |
15 files changed, 37 insertions, 23 deletions
diff --git a/coccinelle/equals-null.cocci b/coccinelle/equals-null.cocci new file mode 100644 index 0000000000..957d828a83 --- /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/analyze/analyze-verify.c b/src/analyze/analyze-verify.c index 3128d152ac..461e7852ac 100644 --- a/src/analyze/analyze-verify.c +++ b/src/analyze/analyze-verify.c @@ -147,7 +147,7 @@ static int verify_socket(Unit *u) { } static int verify_executable(Unit *u, ExecCommand *exec) { - if (exec == NULL) + if (!exec) return 0; if (access(exec->path, X_OK) < 0) diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 8b220d1978..d45c1dc496 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -416,7 +416,7 @@ static int acquire_time_data(sd_bus *bus, struct unit_times **out) { continue; t->name = strdup(u.id); - if (t->name == NULL) { + if (!t->name) { r = log_oom(); goto fail; } @@ -820,7 +820,7 @@ static int list_dependencies_get_dependencies(sd_bus *bus, const char *name, cha assert(deps); path = unit_dbus_path_from_name(name); - if (path == NULL) + if (!path) return -ENOMEM; return bus_get_unit_property_strv(bus, path, "After", deps); @@ -878,7 +878,7 @@ static int list_dependencies_one(sd_bus *bus, const char *name, unsigned int lev } } - if (service_longest == 0 ) + if (service_longest == 0) return r; STRV_FOREACH(c, deps) { @@ -937,7 +937,7 @@ static int list_dependencies(sd_bus *bus, const char *name) { assert(bus); path = unit_dbus_path_from_name(name); - if (path == NULL) + if (!path) return -ENOMEM; r = sd_bus_get_property( diff --git a/src/basic/clock-util.c b/src/basic/clock-util.c index 232a7ad208..e2499099b6 100644 --- a/src/basic/clock-util.c +++ b/src/basic/clock-util.c @@ -73,7 +73,7 @@ int clock_set_hwclock(const struct tm *tm) { int clock_is_localtime(const char* adjtime_path) { _cleanup_fclose_ FILE *f; - if (adjtime_path == NULL) + if (!adjtime_path) adjtime_path = "/etc/adjtime"; /* diff --git a/src/basic/device-nodes.c b/src/basic/device-nodes.c index 92e1f7f0bd..61dc49238c 100644 --- a/src/basic/device-nodes.c +++ b/src/basic/device-nodes.c @@ -40,7 +40,7 @@ int whitelisted_char_for_devnode(char c, const char *white) { int encode_devnode_name(const char *str, char *str_enc, size_t len) { size_t i, j; - if (str == NULL || str_enc == NULL) + if (!str || !str_enc) return -EINVAL; for (i = 0, j = 0; str[i] != '\0'; i++) { diff --git a/src/basic/ether-addr-util.c b/src/basic/ether-addr-util.c index d94bdbd149..bbe8bf0006 100644 --- a/src/basic/ether-addr-util.c +++ b/src/basic/ether-addr-util.c @@ -71,7 +71,7 @@ int ether_addr_from_string(const char *s, struct ether_addr *ret, size_t *offset if (s[pos] == '\0') \ break; \ hexoff = strchr(hex, s[pos]); \ - if (hexoff == NULL) \ + if (!hexoff) \ break; \ assert(hexoff >= hex); \ x = hexoff - hex; \ @@ -99,7 +99,7 @@ int ether_addr_from_string(const char *s, struct ether_addr *ret, size_t *offset sep = s[strspn(s, hex)]; if (sep == '\n') return -EINVAL; - if (strchr(":.-", sep) == NULL) + if (!strchr(":.-", sep)) return -EINVAL; if (sep == '.') { diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 12d6d06fa2..1ce7b85fba 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -140,7 +140,7 @@ int write_string_file_ts( return r; } else - assert(ts == NULL); + assert(!ts); if (flags & WRITE_STRING_FILE_CREATE) { f = fopen(fn, "we"); @@ -1191,7 +1191,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/journal-importer.c b/src/basic/journal-importer.c index 2afb530bae..6942c370cb 100644 --- a/src/basic/journal-importer.c +++ b/src/basic/journal-importer.c @@ -96,7 +96,7 @@ static int get_line(JournalImporter *imp, char **line, size_t *size) { assert(imp->state == IMPORTER_STATE_LINE); assert(imp->offset <= imp->filled); assert(imp->filled <= imp->size); - assert(imp->buf == NULL || imp->size > 0); + assert(!imp->buf || imp->size > 0); assert(imp->fd >= 0); for (;;) { @@ -159,8 +159,8 @@ static int fill_fixed_size(JournalImporter *imp, void **data, size_t size) { assert(size <= DATA_SIZE_MAX); assert(imp->offset <= imp->filled); assert(imp->filled <= imp->size); - assert(imp->buf != NULL || imp->size == 0); - assert(imp->buf == NULL || imp->size > 0); + assert(imp->buf || imp->size == 0); + assert(!imp->buf || imp->size > 0); assert(imp->fd >= 0); assert(data); diff --git a/src/basic/path-util.c b/src/basic/path-util.c index fe20799ba2..ab4778d4ed 100644 --- a/src/basic/path-util.c +++ b/src/basic/path-util.c @@ -538,7 +538,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 bd5a6ae613..d56576ddbe 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -893,7 +893,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); diff --git a/src/boot/efi/measure.c b/src/boot/efi/measure.c index 94823587e8..be4fea84a2 100644 --- a/src/boot/efi/measure.c +++ b/src/boot/efi/measure.c @@ -201,7 +201,7 @@ static EFI_STATUS tpm1_measure_to_pcr_and_event_log(const EFI_TCG *tcg, UINT32 p tcg_event = AllocateZeroPool(desc_len + sizeof(TCG_PCR_EVENT)); - if (tcg_event == NULL) + if (!tcg_event) return EFI_OUT_OF_RESOURCES; tcg_event->EventSize = desc_len; @@ -255,7 +255,7 @@ static EFI_STATUS tpm2_measure_to_pcr_and_event_log(const EFI_TCG2 *tcg, UINT32 tcg_event = AllocateZeroPool(sizeof(*tcg_event) - sizeof(tcg_event->Event) + desc_len + 1); - if (tcg_event == NULL) + if (!tcg_event) return EFI_OUT_OF_RESOURCES; tcg_event->Size = sizeof(*tcg_event) - sizeof(tcg_event->Event) + desc_len + 1; diff --git a/src/core/execute.c b/src/core/execute.c index acd767cf77..f20246796f 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -3854,7 +3854,7 @@ int exec_context_load_environment(Unit *unit, const ExecContext *c, char ***l) { p = strv_env_clean_with_callback(p, invalid_env, &info); } - if (r == NULL) + if (!r) r = p; else { char **m; diff --git a/src/core/main.c b/src/core/main.c index 4995446c51..d79e183a72 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1479,7 +1479,7 @@ static int become_shutdown( int r; assert(shutdown_verb); - assert(command_line[pos] == NULL); + assert(!command_line[pos]); env_block = strv_copy(environ); xsprintf(log_level, "%d", log_get_max_level()); diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index ead04d4ee1..c7dd61f077 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -559,7 +559,7 @@ static int compose_open_fds(pid_t pid, char **open_fds) { continue; fdinfo = fdopen(fd, "re"); - if (fdinfo == NULL) { + if (!fdinfo) { close(fd); continue; } diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index c928741a4e..e19a1637bf 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -335,7 +335,7 @@ static int find_source_vc(char **ret_path, unsigned *ret_idx) { int ret_fd, r, err = 0; path = new(char, sizeof("/dev/tty63")); - if (path == NULL) + if (!path) return log_oom(); for (i = 1; i <= 63; i++) { @@ -396,7 +396,7 @@ static int verify_source_vc(char **ret_path, const char *src_vc) { return log_error_errno(r, "Virtual console %s is not in K_XLATE or K_UNICODE: %m", src_vc); path = strdup(src_vc); - if (path == NULL) + if (!path) return log_oom(); *ret_path = path; |