• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 23966986054

03 Apr 2026 09:22PM UTC coverage: 72.107% (-0.3%) from 72.362%
23966986054

push

github

daandemeyer
fd-util: Add missing assert()

1 of 1 new or added line in 1 file covered. (100.0%)

7891 existing lines in 120 files now uncovered.

318256 of 441368 relevant lines covered (72.11%)

1186882.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.11
/src/basic/hash-funcs.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include <stdlib.h>
4
#include <string.h>
5
#include <sys/sysmacros.h>
6

7
#include "hash-funcs.h"
8
#include "path-util.h"
9
#include "siphash24.h"
10
#include "strv.h"
11

12
void string_hash_func(const char *p, struct siphash *state) {
108,397,945✔
13
        siphash24_compress(p, strlen(p) + 1, state);
108,397,945✔
14
}
108,397,945✔
15

16
DEFINE_HASH_OPS(string_hash_ops,
17
                char, string_hash_func, string_compare_func);
18
DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(
677,992✔
19
                string_hash_ops_free,
20
                char, string_hash_func, string_compare_func, free);
21
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
48✔
22
                string_hash_ops_value_free,
23
                char, string_hash_func, string_compare_func,
24
                void, free);
25
DEFINE_HASH_OPS_FULL(
25,379,988✔
26
                string_hash_ops_free_free,
27
                char, string_hash_func, string_compare_func, free,
28
                void, free);
29
DEFINE_HASH_OPS_FULL(
660,622✔
30
                string_hash_ops_free_strv_free,
31
                char, string_hash_func, string_compare_func, free,
32
                char*, strv_free);
33

34
void path_hash_func(const char *p, struct siphash *state) {
32,963,742✔
35
        bool add_slash = false;
32,963,742✔
36

37
        assert(p);
32,963,742✔
38
        assert(state);
32,963,742✔
39

40
        /* Calculates a hash for a path in a way this duplicate inner slashes don't make a differences, and also
41
         * whether there's a trailing slash or not. This fits well with the semantics of path_compare(), which does
42
         * similar checks and also doesn't care for trailing slashes. Note that relative and absolute paths (i.e. those
43
         * which begin in a slash or not) will hash differently though. */
44

45
        /* if path is absolute, add one "/" to the hash. */
46
        if (path_is_absolute(p))
32,963,742✔
47
                siphash24_compress_byte('/', state);
27,812,502✔
48

49
        for (;;) {
338,159,356✔
50
                const char *e;
185,561,549✔
51
                int r;
185,561,549✔
52

53
                r = path_find_first_component(&p, true, &e);
185,561,549✔
54
                if (r == 0)
185,561,549✔
55
                        return;
32,963,742✔
56

57
                if (add_slash)
152,597,959✔
58
                        siphash24_compress_byte('/', state);
119,726,544✔
59

60
                if (r < 0) {
152,597,959✔
61
                        /* if a component is invalid, then add remaining part as a string. */
62
                        string_hash_func(p, state);
152✔
63
                        return;
152✔
64
                }
65

66
                /* Add this component to the hash. */
67
                siphash24_compress(e, r, state);
152,597,807✔
68

69
                add_slash = true;
152,597,807✔
70
        }
71
}
72

73
DEFINE_HASH_OPS(path_hash_ops,
74
                char, path_hash_func, path_compare);
75
DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(
1,471,266✔
76
                path_hash_ops_free,
77
                char, path_hash_func, path_compare, free);
78
DEFINE_HASH_OPS_FULL(
188,146✔
79
                path_hash_ops_free_free,
80
                char, path_hash_func, path_compare, free,
81
                void, free);
82

83
void trivial_hash_func(const void *p, struct siphash *state) {
34,865,429✔
84
        siphash24_compress_typesafe(p, state);
34,865,429✔
85
}
34,865,429✔
86

87
int trivial_compare_func(const void *a, const void *b) {
21,770,175✔
88
        return CMP(a, b);
21,770,175✔
89
}
90

91
DEFINE_HASH_OPS(trivial_hash_ops,
92
                void, trivial_hash_func, trivial_compare_func);
93
DEFINE_HASH_OPS_WITH_KEY_DESTRUCTOR(
9,056✔
94
                trivial_hash_ops_free,
95
                void, trivial_hash_func, trivial_compare_func, free);
96
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
5,965✔
97
                trivial_hash_ops_value_free,
98
                void, trivial_hash_func, trivial_compare_func,
99
                void, free);
100
DEFINE_HASH_OPS_FULL(
3,606✔
101
                trivial_hash_ops_free_free,
102
                void, trivial_hash_func, trivial_compare_func, free,
103
                void, free);
104

105
void uint64_hash_func(const uint64_t *p, struct siphash *state) {
68,907,642✔
106
        assert(p);
68,907,642✔
107

108
        siphash24_compress_typesafe(*p, state);
68,907,642✔
109
}
68,907,642✔
110

111
int uint64_compare_func(const uint64_t *a, const uint64_t *b) {
67,011,223✔
112
        assert(a);
67,011,223✔
113
        assert(b);
67,011,223✔
114

115
        return CMP(*a, *b);
67,011,223✔
116
}
117

118
DEFINE_HASH_OPS(uint64_hash_ops,
119
                uint64_t, uint64_hash_func, uint64_compare_func);
120
DEFINE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
16,576✔
121
                uint64_hash_ops_value_free,
122
                uint64_t, uint64_hash_func, uint64_compare_func,
123
                void, free);
124

125
#if SIZEOF_DEV_T != 8
126
void devt_hash_func(const dev_t *p, struct siphash *state) {
127
        assert(p);
128

129
        siphash24_compress_typesafe(*p, state);
130
}
131
#endif
132

133
int devt_compare_func(const dev_t *a, const dev_t *b) {
22✔
134
        int r;
22✔
135

136
        assert(a);
22✔
137
        assert(b);
22✔
138

139
        r = CMP(major(*a), major(*b));
22✔
140
        if (r != 0)
22✔
UNCOV
141
                return r;
×
142

143
        return CMP(minor(*a), minor(*b));
22✔
144
}
145

146
DEFINE_HASH_OPS(devt_hash_ops, dev_t, devt_hash_func, devt_compare_func);
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc