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

systemd / systemd / 15232239991

24 May 2025 08:01PM UTC coverage: 72.053% (-0.02%) from 72.07%
15232239991

push

github

web-flow
docs: add man pages for sd_device_enumerator_[new,ref,unref,unrefp] (#37586)

For #20929.

299160 of 415197 relevant lines covered (72.05%)

703671.29 hits per line

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

90.27
/src/shared/xml.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "string-util.h"
4
#include "xml.h"
5

6
enum {
7
        STATE_NULL,
8
        STATE_TEXT,
9
        STATE_TAG,
10
        STATE_ATTRIBUTE,
11
};
12

13
static void inc_lines(unsigned *line, const char *s, size_t n) {
1,411,551✔
14
        const char *p = s;
1,411,551✔
15

16
        if (!line)
1,411,551✔
17
                return;
18

19
        for (;;) {
×
20
                const char *f;
×
21

22
                f = memchr(p, '\n', n);
×
23
                if (!f)
×
24
                        return;
25

26
                n -= (f - p) + 1;
×
27
                p = f + 1;
×
28
                (*line)++;
×
29
        }
30
}
31

32
/* We don't actually do real XML here. We only read a simplistic
33
 * subset, that is a bit less strict that XML and lacks all the more
34
 * complex features, like entities, or namespaces. However, we do
35
 * support some HTML5-like simplifications */
36

37
int xml_tokenize(const char **p, char **name, void **state, unsigned *line) {
1,499,748✔
38
        const char *c, *e, *b;
1,499,748✔
39
        char *ret;
1,499,748✔
40
        int t;
1,499,748✔
41

42
        assert(p);
1,499,748✔
43
        assert(*p);
1,499,748✔
44
        assert(name);
1,499,748✔
45
        assert(state);
1,499,748✔
46

47
        t = PTR_TO_INT(*state);
1,499,748✔
48
        c = *p;
1,499,748✔
49

50
        if (t == STATE_NULL) {
1,499,748✔
51
                if (line)
380✔
52
                        *line = 1;
×
53
                t = STATE_TEXT;
54
        }
55

56
        for (;;) {
1,679,108✔
57
                if (*c == 0)
1,679,108✔
58
                        return XML_END;
59

60
                switch (t) {
1,678,728✔
61

62
                case STATE_TEXT: {
535,104✔
63
                        int x;
535,104✔
64

65
                        e = strchrnul(c, '<');
535,104✔
66
                        if (e > c) {
535,104✔
67
                                /* More text... */
68
                                ret = strndup(c, e - c);
267,550✔
69
                                if (!ret)
267,550✔
70
                                        return -ENOMEM;
71

72
                                inc_lines(line, c, e - c);
267,550✔
73

74
                                *name = ret;
267,550✔
75
                                *p = e;
267,550✔
76
                                *state = INT_TO_PTR(STATE_TEXT);
267,550✔
77

78
                                return XML_TEXT;
267,550✔
79
                        }
80

81
                        assert(*e == '<');
267,554✔
82
                        b = c + 1;
267,554✔
83

84
                        if (startswith(b, "!--")) {
267,554✔
85
                                /* A comment */
86
                                e = strstrafter(b + 3, "-->");
1✔
87
                                if (!e)
1✔
88
                                        return -EINVAL;
89

90
                                inc_lines(line, b, e - b);
1✔
91

92
                                c = e;
1✔
93
                                continue;
1✔
94
                        }
95

96
                        if (*b == '?') {
267,553✔
97
                                /* Processing instruction */
98

99
                                e = strstrafter(b + 1, "?>");
1✔
100
                                if (!e)
1✔
101
                                        return -EINVAL;
102

103
                                inc_lines(line, b, e - b);
1✔
104

105
                                c = e;
1✔
106
                                continue;
1✔
107
                        }
108

109
                        if (*b == '!') {
267,552✔
110
                                /* DTD */
111

112
                                e = strchr(b + 1, '>');
376✔
113
                                if (!e)
376✔
114
                                        return -EINVAL;
115

116
                                inc_lines(line, b, e + 1 - b);
376✔
117

118
                                c = e + 1;
376✔
119
                                continue;
376✔
120
                        }
121

122
                        if (*b == '/') {
267,176✔
123
                                /* A closing tag */
124
                                x = XML_TAG_CLOSE;
89,491✔
125
                                b++;
89,491✔
126
                        } else
127
                                x = XML_TAG_OPEN;
128

129
                        e = strpbrk(b, WHITESPACE "/>");
267,176✔
130
                        if (!e)
267,176✔
131
                                return -EINVAL;
132

133
                        ret = strndup(b, e - b);
267,176✔
134
                        if (!ret)
267,176✔
135
                                return -ENOMEM;
136

137
                        *name = ret;
267,176✔
138
                        *p = e;
267,176✔
139
                        *state = INT_TO_PTR(STATE_TAG);
267,176✔
140

141
                        return x;
267,176✔
142
                }
143

144
                case STATE_TAG:
705,400✔
145

146
                        b = c + strspn(c, WHITESPACE);
705,400✔
147
                        if (*b == 0)
705,400✔
148
                                return -EINVAL;
149

150
                        inc_lines(line, c, b - c);
705,400✔
151

152
                        e = b + strcspn(b, WHITESPACE "=/>");
705,400✔
153
                        if (e > b) {
705,400✔
154
                                /* An attribute */
155

156
                                ret = strndup(b, e - b);
438,224✔
157
                                if (!ret)
438,224✔
158
                                        return -ENOMEM;
159

160
                                *name = ret;
438,224✔
161
                                *p = e;
438,224✔
162
                                *state = INT_TO_PTR(STATE_ATTRIBUTE);
438,224✔
163

164
                                return XML_ATTRIBUTE_NAME;
438,224✔
165
                        }
166

167
                        if (startswith(b, "/>")) {
267,176✔
168
                                /* An empty tag */
169

170
                                *name = NULL; /* For empty tags we return a NULL name, the caller must be prepared for that */
88,194✔
171
                                *p = b + 2;
88,194✔
172
                                *state = INT_TO_PTR(STATE_TEXT);
88,194✔
173

174
                                return XML_TAG_CLOSE_EMPTY;
88,194✔
175
                        }
176

177
                        if (*b != '>')
178,982✔
178
                                return -EINVAL;
179

180
                        c = b + 1;
178,982✔
181
                        t = STATE_TEXT;
178,982✔
182
                        continue;
178,982✔
183

184
                case STATE_ATTRIBUTE:
438,224✔
185

186
                        if (*c == '=') {
438,224✔
187
                                c++;
438,224✔
188

189
                                if (IN_SET(*c, '\'', '"')) {
438,224✔
190
                                        /* Tag with a quoted value */
191

192
                                        e = strchr(c+1, *c);
438,223✔
193
                                        if (!e)
438,223✔
194
                                                return -EINVAL;
195

196
                                        inc_lines(line, c, e - c);
438,223✔
197

198
                                        ret = strndup(c+1, e - c - 1);
438,223✔
199
                                        if (!ret)
438,223✔
200
                                                return -ENOMEM;
201

202
                                        *name = ret;
438,223✔
203
                                        *p = e + 1;
438,223✔
204
                                        *state = INT_TO_PTR(STATE_TAG);
438,223✔
205

206
                                        return XML_ATTRIBUTE_VALUE;
438,223✔
207

208
                                }
209

210
                                /* Tag with a value without quotes */
211

212
                                b = strpbrk(c, WHITESPACE ">");
1✔
213
                                if (!b)
1✔
214
                                        b = c;
×
215

216
                                ret = strndup(c, b - c);
1✔
217
                                if (!ret)
1✔
218
                                        return -ENOMEM;
219

220
                                *name = ret;
1✔
221
                                *p = b;
1✔
222
                                *state = INT_TO_PTR(STATE_TAG);
1✔
223
                                return XML_ATTRIBUTE_VALUE;
1✔
224
                        }
225

226
                        t = STATE_TAG;
×
227
                        continue;
×
228
                }
229

230
        }
231

232
        assert_not_reached();
233
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc