Bug Summary

File:build-scan/../src/test/test-stat-util.c
Warning:line 78, column 9
Value stored to 'fd' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test-stat-util.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I test-stat-util.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/test/test-stat-util.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include <fcntl.h>
4#include <linux1/magic.h>
5#include <unistd.h>
6
7#include "alloc-util.h"
8#include "fd-util.h"
9#include "fileio.h"
10#include "macro.h"
11#include "missing.h"
12#include "mount-util.h"
13#include "stat-util.h"
14
15static void test_files_same(void) {
16 _cleanup_close___attribute__((cleanup(closep))) int fd = -1;
17 char name[] = "/tmp/test-files_same.XXXXXX";
18 char name_alias[] = "/tmp/test-files_same.alias";
19
20 fd = mkostemp_safe(name);
21 assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-stat-util.c"
, 21, __PRETTY_FUNCTION__); } while (0)
;
22 assert_se(symlink(name, name_alias) >= 0)do { if ((__builtin_expect(!!(!(symlink(name, name_alias) >=
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(name, name_alias) >= 0"
), "../src/test/test-stat-util.c", 22, __PRETTY_FUNCTION__); }
while (0)
;
23
24 assert_se(files_same(name, name, 0))do { if ((__builtin_expect(!!(!(files_same(name, name, 0))),0
))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("files_same(name, name, 0)"
), "../src/test/test-stat-util.c", 24, __PRETTY_FUNCTION__); }
while (0)
;
25 assert_se(files_same(name, name, AT_SYMLINK_NOFOLLOW))do { if ((__builtin_expect(!!(!(files_same(name, name, 0x100)
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("files_same(name, name, AT_SYMLINK_NOFOLLOW)"
), "../src/test/test-stat-util.c", 25, __PRETTY_FUNCTION__); }
while (0)
;
26 assert_se(files_same(name, name_alias, 0))do { if ((__builtin_expect(!!(!(files_same(name, name_alias, 0
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("files_same(name, name_alias, 0)"
), "../src/test/test-stat-util.c", 26, __PRETTY_FUNCTION__); }
while (0)
;
27 assert_se(!files_same(name, name_alias, AT_SYMLINK_NOFOLLOW))do { if ((__builtin_expect(!!(!(!files_same(name, name_alias,
0x100))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!files_same(name, name_alias, AT_SYMLINK_NOFOLLOW)"
), "../src/test/test-stat-util.c", 27, __PRETTY_FUNCTION__); }
while (0)
;
28
29 unlink(name);
30 unlink(name_alias);
31}
32
33static void test_is_symlink(void) {
34 char name[] = "/tmp/test-is_symlink.XXXXXX";
35 char name_link[] = "/tmp/test-is_symlink.link";
36 _cleanup_close___attribute__((cleanup(closep))) int fd = -1;
37
38 fd = mkostemp_safe(name);
39 assert_se(fd >= 0)do { if ((__builtin_expect(!!(!(fd >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("fd >= 0"), "../src/test/test-stat-util.c"
, 39, __PRETTY_FUNCTION__); } while (0)
;
40 assert_se(symlink(name, name_link) >= 0)do { if ((__builtin_expect(!!(!(symlink(name, name_link) >=
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("symlink(name, name_link) >= 0"
), "../src/test/test-stat-util.c", 40, __PRETTY_FUNCTION__); }
while (0)
;
41
42 assert_se(is_symlink(name) == 0)do { if ((__builtin_expect(!!(!(is_symlink(name) == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("is_symlink(name) == 0"), "../src/test/test-stat-util.c"
, 42, __PRETTY_FUNCTION__); } while (0)
;
43 assert_se(is_symlink(name_link) == 1)do { if ((__builtin_expect(!!(!(is_symlink(name_link) == 1)),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("is_symlink(name_link) == 1"
), "../src/test/test-stat-util.c", 43, __PRETTY_FUNCTION__); }
while (0)
;
44 assert_se(is_symlink("/a/file/which/does/not/exist/i/guess") < 0)do { if ((__builtin_expect(!!(!(is_symlink("/a/file/which/does/not/exist/i/guess"
) < 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("is_symlink(\"/a/file/which/does/not/exist/i/guess\") < 0"
), "../src/test/test-stat-util.c", 44, __PRETTY_FUNCTION__); }
while (0)
;
45
46 unlink(name);
47 unlink(name_link);
48}
49
50static void test_path_is_fs_type(void) {
51 /* run might not be a mount point in build chroots */
52 if (path_is_mount_point("/run", NULL((void*)0), AT_SYMLINK_FOLLOW0x400) > 0) {
53 assert_se(path_is_fs_type("/run", TMPFS_MAGIC) > 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/run", 0x01021994
) > 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/run\", TMPFS_MAGIC) > 0"
), "../src/test/test-stat-util.c", 53, __PRETTY_FUNCTION__); }
while (0)
;
54 assert_se(path_is_fs_type("/run", BTRFS_SUPER_MAGIC) == 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/run", 0x9123683E
) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/run\", BTRFS_SUPER_MAGIC) == 0"
), "../src/test/test-stat-util.c", 54, __PRETTY_FUNCTION__); }
while (0)
;
55 }
56 assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC) > 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/proc", 0x9fa0
) > 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/proc\", PROC_SUPER_MAGIC) > 0"
), "../src/test/test-stat-util.c", 56, __PRETTY_FUNCTION__); }
while (0)
;
57 assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/proc", 0x9123683E
) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/proc\", BTRFS_SUPER_MAGIC) == 0"
), "../src/test/test-stat-util.c", 57, __PRETTY_FUNCTION__); }
while (0)
;
58 assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0)do { if ((__builtin_expect(!!(!(path_is_fs_type("/proc", 0x9123683E
) == 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_fs_type(\"/proc\", BTRFS_SUPER_MAGIC) == 0"
), "../src/test/test-stat-util.c", 58, __PRETTY_FUNCTION__); }
while (0)
;
59 assert_se(path_is_fs_type("/i-dont-exist", BTRFS_SUPER_MAGIC) == -ENOENT)do { if ((__builtin_expect(!!(!(path_is_fs_type("/i-dont-exist"
, 0x9123683E) == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("path_is_fs_type(\"/i-dont-exist\", BTRFS_SUPER_MAGIC) == -ENOENT"
), "../src/test/test-stat-util.c", 59, __PRETTY_FUNCTION__); }
while (0)
;
60}
61
62static void test_path_is_temporary_fs(void) {
63 /* run might not be a mount point in build chroots */
64 if (path_is_mount_point("/run", NULL((void*)0), AT_SYMLINK_FOLLOW0x400) > 0)
65 assert_se(path_is_temporary_fs("/run") > 0)do { if ((__builtin_expect(!!(!(path_is_temporary_fs("/run") >
0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_temporary_fs(\"/run\") > 0"
), "../src/test/test-stat-util.c", 65, __PRETTY_FUNCTION__); }
while (0)
;
66 assert_se(path_is_temporary_fs("/proc") == 0)do { if ((__builtin_expect(!!(!(path_is_temporary_fs("/proc")
== 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_temporary_fs(\"/proc\") == 0"
), "../src/test/test-stat-util.c", 66, __PRETTY_FUNCTION__); }
while (0)
;
67 assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT)do { if ((__builtin_expect(!!(!(path_is_temporary_fs("/i-dont-exist"
) == -2)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("path_is_temporary_fs(\"/i-dont-exist\") == -ENOENT"
), "../src/test/test-stat-util.c", 67, __PRETTY_FUNCTION__); }
while (0)
;
68}
69
70static void test_fd_is_network_ns(void) {
71 _cleanup_close___attribute__((cleanup(closep))) int fd = -1;
72 assert_se(fd_is_network_ns(STDIN_FILENO) == 0)do { if ((__builtin_expect(!!(!(fd_is_network_ns(0) == 0)),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fd_is_network_ns(STDIN_FILENO) == 0"
), "../src/test/test-stat-util.c", 72, __PRETTY_FUNCTION__); }
while (0)
;
73 assert_se(fd_is_network_ns(STDERR_FILENO) == 0)do { if ((__builtin_expect(!!(!(fd_is_network_ns(2) == 0)),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fd_is_network_ns(STDERR_FILENO) == 0"
), "../src/test/test-stat-util.c", 73, __PRETTY_FUNCTION__); }
while (0)
;
74 assert_se(fd_is_network_ns(STDOUT_FILENO) == 0)do { if ((__builtin_expect(!!(!(fd_is_network_ns(1) == 0)),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("fd_is_network_ns(STDOUT_FILENO) == 0"
), "../src/test/test-stat-util.c", 74, __PRETTY_FUNCTION__); }
while (0)
;
75
76 assert_se((fd = open("/proc/self/ns/mnt", O_CLOEXEC|O_RDONLY)) >= 0)do { if ((__builtin_expect(!!(!((fd = open("/proc/self/ns/mnt"
, 02000000|00)) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("(fd = open(\"/proc/self/ns/mnt\", O_CLOEXEC|O_RDONLY)) >= 0"
), "../src/test/test-stat-util.c", 76, __PRETTY_FUNCTION__); }
while (0)
;
77 assert_se(IN_SET(fd_is_network_ns(fd), 0, -EUCLEAN))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__
((unused)) char _static_assert__macros_need_to_be_extended[20
- sizeof((int[]){0, -117})/sizeof(int)]; switch(fd_is_network_ns
(fd)) { case 0: case -117: _found = 1; break; default: break;
} _found; }))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("IN_SET(fd_is_network_ns(fd), 0, -EUCLEAN)"), "../src/test/test-stat-util.c"
, 77, __PRETTY_FUNCTION__); } while (0)
;
78 fd = safe_close(fd);
Value stored to 'fd' is never read
79
80 assert_se((fd = open("/proc/self/ns/net", O_CLOEXEC|O_RDONLY)) >= 0)do { if ((__builtin_expect(!!(!((fd = open("/proc/self/ns/net"
, 02000000|00)) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("(fd = open(\"/proc/self/ns/net\", O_CLOEXEC|O_RDONLY)) >= 0"
), "../src/test/test-stat-util.c", 80, __PRETTY_FUNCTION__); }
while (0)
;
81 assert_se(IN_SET(fd_is_network_ns(fd), 1, -EUCLEAN))do { if ((__builtin_expect(!!(!(({ _Bool _found = 0; static __attribute__
((unused)) char _static_assert__macros_need_to_be_extended[20
- sizeof((int[]){1, -117})/sizeof(int)]; switch(fd_is_network_ns
(fd)) { case 1: case -117: _found = 1; break; default: break;
} _found; }))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("IN_SET(fd_is_network_ns(fd), 1, -EUCLEAN)"), "../src/test/test-stat-util.c"
, 81, __PRETTY_FUNCTION__); } while (0)
;
82}
83
84int main(int argc, char *argv[]) {
85 test_files_same();
86 test_is_symlink();
87 test_path_is_fs_type();
88 test_path_is_temporary_fs();
89 test_fd_is_network_ns();
90
91 return 0;
92}