Bug Summary

File:build-scan/../src/test/test-umount.c
Warning:line 41, column 25
Although the value stored to 'testdata_fname' is used in the enclosing expression, the value is never actually read from 'testdata_fname'

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-umount.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-umount.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 -I /usr/include/libmount -I /usr/include/blkid -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-umount.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include "alloc-util.h"
4#include "log.h"
5#include "path-util.h"
6#include "string-util.h"
7#include "tests.h"
8#include "umount.h"
9#include "util.h"
10
11static void test_mount_points_list(const char *fname) {
12 _cleanup_(mount_points_list_free)__attribute__((cleanup(mount_points_list_free))) LIST_HEAD(MountPoint, mp_list_head)MountPoint *mp_list_head;
13 _cleanup_free___attribute__((cleanup(freep))) char *testdata_fname = NULL((void*)0);
14 MountPoint *m;
15
16 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/self/mountinfo")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 16, __func__, "/* %s(\"%s\") */"
, __func__, fname ?: "/proc/self/mountinfo") : -abs(_e); })
;
17
18 if (fname)
19 fname = testdata_fname = path_join(NULL((void*)0), get_testdata_dir(), fname);
20
21 LIST_HEAD_INIT(mp_list_head)do { (mp_list_head) = ((void*)0); } while (0);
22 assert_se(mount_points_list_get(fname, &mp_list_head) >= 0)do { if ((__builtin_expect(!!(!(mount_points_list_get(fname, &
mp_list_head) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("mount_points_list_get(fname, &mp_list_head) >= 0")
, "../src/test/test-umount.c", 22, __PRETTY_FUNCTION__); } while
(0)
;
23
24 LIST_FOREACH(mount_point, m, mp_list_head)for ((m) = (mp_list_head); (m); (m) = (m)->mount_point_next
)
25 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 30, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
26 m->path,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 30, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
27 strempty(m->remount_options),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 30, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
28 m->remount_flags,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 30, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
29 yes_no(m->try_remount_ro),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 30, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
30 major(m->devnum), minor(m->devnum))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 30, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
;
31}
32
33static void test_swap_list(const char *fname) {
34 _cleanup_(mount_points_list_free)__attribute__((cleanup(mount_points_list_free))) LIST_HEAD(MountPoint, mp_list_head)MountPoint *mp_list_head;
35 _cleanup_free___attribute__((cleanup(freep))) char *testdata_fname = NULL((void*)0);
36 MountPoint *m;
37
38 log_info("/* %s(\"%s\") */", __func__, fname ?: "/proc/swaps")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 38, __func__, "/* %s(\"%s\") */"
, __func__, fname ?: "/proc/swaps") : -abs(_e); })
;
39
40 if (fname)
41 fname = testdata_fname = path_join(NULL((void*)0), get_testdata_dir(), fname);
Although the value stored to 'testdata_fname' is used in the enclosing expression, the value is never actually read from 'testdata_fname'
42
43 LIST_HEAD_INIT(mp_list_head)do { (mp_list_head) = ((void*)0); } while (0);
44 assert_se(swap_list_get(fname, &mp_list_head) >= 0)do { if ((__builtin_expect(!!(!(swap_list_get(fname, &mp_list_head
) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"swap_list_get(fname, &mp_list_head) >= 0"), "../src/test/test-umount.c"
, 44, __PRETTY_FUNCTION__); } while (0)
;
45
46 LIST_FOREACH(mount_point, m, mp_list_head)for ((m) = (mp_list_head); (m); (m) = (m)->mount_point_next
)
47 log_debug("path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 52, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
48 m->path,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 52, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
49 strempty(m->remount_options),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 52, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
50 m->remount_flags,({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 52, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
51 yes_no(m->try_remount_ro),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 52, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
52 major(m->devnum), minor(m->devnum))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/test/test-umount.c", 52, __func__, "path=%s o=%s f=0x%lx try-ro=%s dev=%u:%u"
, m->path, strempty(m->remount_options), m->remount_flags
, yes_no(m->try_remount_ro), gnu_dev_major (m->devnum),
gnu_dev_minor (m->devnum)) : -abs(_e); })
;
53}
54
55int main(int argc, char **argv) {
56 log_set_max_level(LOG_DEBUG)log_set_max_level_realm(LOG_REALM_SYSTEMD, (7));
57 log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD);
58 log_open();
59
60 test_mount_points_list(NULL((void*)0));
61 test_mount_points_list("/test-umount/empty.mountinfo");
62 test_mount_points_list("/test-umount/garbled.mountinfo");
63 test_mount_points_list("/test-umount/rhbug-1554943.mountinfo");
64
65 test_swap_list(NULL((void*)0));
66 test_swap_list("/test-umount/example.swaps");
67}