Bug Summary

File:build-scan/../src/test/test-set.c
Warning:line 41, column 9
Value stored to 'm' 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-set.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-set.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-set.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include "set.h"
4
5static void test_set_steal_first(void) {
6 _cleanup_set_free___attribute__((cleanup(set_freep))) Set *m = NULL((void*)0);
7 int seen[3] = {};
8 char *val;
9
10 m = set_new(&string_hash_ops)internal_set_new(&string_hash_ops );
11 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-set.c", 11, __PRETTY_FUNCTION__
); } while (0)
;
12
13 assert_se(set_put(m, (void*) "1") == 1)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "1") == 1)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"1\") == 1"
), "../src/test/test-set.c", 13, __PRETTY_FUNCTION__); } while
(0)
;
14 assert_se(set_put(m, (void*) "22") == 1)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "22") == 1
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"22\") == 1"
), "../src/test/test-set.c", 14, __PRETTY_FUNCTION__); } while
(0)
;
15 assert_se(set_put(m, (void*) "333") == 1)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "333") == 1
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"333\") == 1"
), "../src/test/test-set.c", 15, __PRETTY_FUNCTION__); } while
(0)
;
16
17 while ((val = set_steal_first(m)))
18 seen[strlen(val) - 1]++;
19
20 assert_se(seen[0] == 1 && seen[1] == 1 && seen[2] == 1)do { if ((__builtin_expect(!!(!(seen[0] == 1 && seen[
1] == 1 && seen[2] == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("seen[0] == 1 && seen[1] == 1 && seen[2] == 1"
), "../src/test/test-set.c", 20, __PRETTY_FUNCTION__); } while
(0)
;
21
22 assert_se(set_isempty(m))do { if ((__builtin_expect(!!(!(set_isempty(m))),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("set_isempty(m)"), "../src/test/test-set.c"
, 22, __PRETTY_FUNCTION__); } while (0)
;
23}
24
25typedef struct Item {
26 int seen;
27} Item;
28static void item_seen(Item *item) {
29 item->seen++;
30}
31
32static void test_set_free_with_destructor(void) {
33 Set *m;
34 struct Item items[4] = {};
35 unsigned i;
36
37 assert_se(m = set_new(NULL))do { if ((__builtin_expect(!!(!(m = internal_set_new(((void*)
0) ))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("m = set_new(NULL)"
), "../src/test/test-set.c", 37, __PRETTY_FUNCTION__); } while
(0)
;
38 for (i = 0; i < ELEMENTSOF(items)__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(items), typeof(&*(items))), sizeof(items)/sizeof(
(items)[0]), ((void)0)))
- 1; i++)
39 assert_se(set_put(m, items + i) == 1)do { if ((__builtin_expect(!!(!(set_put(m, items + i) == 1)),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, items + i) == 1"
), "../src/test/test-set.c", 39, __PRETTY_FUNCTION__); } while
(0)
;
40
41 m = set_free_with_destructor(m, item_seen)({ ({ void *_item; while ((_item = set_steal_first(m))) item_seen
(_item); }); set_free(m); })
;
Value stored to 'm' is never read
42 assert_se(items[0].seen == 1)do { if ((__builtin_expect(!!(!(items[0].seen == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("items[0].seen == 1"), "../src/test/test-set.c"
, 42, __PRETTY_FUNCTION__); } while (0)
;
43 assert_se(items[1].seen == 1)do { if ((__builtin_expect(!!(!(items[1].seen == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("items[1].seen == 1"), "../src/test/test-set.c"
, 43, __PRETTY_FUNCTION__); } while (0)
;
44 assert_se(items[2].seen == 1)do { if ((__builtin_expect(!!(!(items[2].seen == 1)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("items[2].seen == 1"), "../src/test/test-set.c"
, 44, __PRETTY_FUNCTION__); } while (0)
;
45 assert_se(items[3].seen == 0)do { if ((__builtin_expect(!!(!(items[3].seen == 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("items[3].seen == 0"), "../src/test/test-set.c"
, 45, __PRETTY_FUNCTION__); } while (0)
;
46}
47
48static void test_set_put(void) {
49 _cleanup_set_free___attribute__((cleanup(set_freep))) Set *m = NULL((void*)0);
50
51 m = set_new(&string_hash_ops)internal_set_new(&string_hash_ops );
52 assert_se(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/test/test-set.c", 52, __PRETTY_FUNCTION__
); } while (0)
;
53
54 assert_se(set_put(m, (void*) "1") == 1)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "1") == 1)
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"1\") == 1"
), "../src/test/test-set.c", 54, __PRETTY_FUNCTION__); } while
(0)
;
55 assert_se(set_put(m, (void*) "22") == 1)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "22") == 1
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"22\") == 1"
), "../src/test/test-set.c", 55, __PRETTY_FUNCTION__); } while
(0)
;
56 assert_se(set_put(m, (void*) "333") == 1)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "333") == 1
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"333\") == 1"
), "../src/test/test-set.c", 56, __PRETTY_FUNCTION__); } while
(0)
;
57 assert_se(set_put(m, (void*) "333") == 0)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "333") == 0
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"333\") == 0"
), "../src/test/test-set.c", 57, __PRETTY_FUNCTION__); } while
(0)
;
58 assert_se(set_remove(m, (void*) "333"))do { if ((__builtin_expect(!!(!(set_remove(m, (void*) "333"))
),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_remove(m, (void*) \"333\")"
), "../src/test/test-set.c", 58, __PRETTY_FUNCTION__); } while
(0)
;
59 assert_se(set_put(m, (void*) "333") == 1)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "333") == 1
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"333\") == 1"
), "../src/test/test-set.c", 59, __PRETTY_FUNCTION__); } while
(0)
;
60 assert_se(set_put(m, (void*) "333") == 0)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "333") == 0
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"333\") == 0"
), "../src/test/test-set.c", 60, __PRETTY_FUNCTION__); } while
(0)
;
61 assert_se(set_put(m, (void*) "22") == 0)do { if ((__builtin_expect(!!(!(set_put(m, (void*) "22") == 0
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("set_put(m, (void*) \"22\") == 0"
), "../src/test/test-set.c", 61, __PRETTY_FUNCTION__); } while
(0)
;
62}
63
64int main(int argc, const char *argv[]) {
65 test_set_steal_first();
66 test_set_free_with_destructor();
67 test_set_put();
68
69 return 0;
70}