Coverage Report

Created: 2026-10-02 06:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/uriparser/src/UriParse.c
Line
Count
Source
1
/*
2
 * uriparser - RFC 3986 URI parsing library
3
 *
4
 * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
5
 * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source  and binary forms, with or without
9
 * modification, are permitted provided  that the following conditions
10
 * are met:
11
 *
12
 *     1. Redistributions  of  source  code   must  retain  the  above
13
 *        copyright notice, this list  of conditions and the following
14
 *        disclaimer.
15
 *
16
 *     2. Redistributions  in binary  form  must  reproduce the  above
17
 *        copyright notice, this list  of conditions and the following
18
 *        disclaimer  in  the  documentation  and/or  other  materials
19
 *        provided with the distribution.
20
 *
21
 *     3. Neither the  name of the  copyright holder nor the  names of
22
 *        its contributors may be used  to endorse or promote products
23
 *        derived from  this software  without specific  prior written
24
 *        permission.
25
 *
26
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
 * "AS IS" AND  ANY EXPRESS OR IMPLIED WARRANTIES,  INCLUDING, BUT NOT
28
 * LIMITED TO,  THE IMPLIED WARRANTIES OF  MERCHANTABILITY AND FITNESS
29
 * FOR  A  PARTICULAR  PURPOSE  ARE  DISCLAIMED.  IN  NO  EVENT  SHALL
30
 * THE  COPYRIGHT HOLDER  OR CONTRIBUTORS  BE LIABLE  FOR ANY  DIRECT,
31
 * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32
 * (INCLUDING, BUT NOT LIMITED TO,  PROCUREMENT OF SUBSTITUTE GOODS OR
33
 * SERVICES; LOSS OF USE, DATA,  OR PROFITS; OR BUSINESS INTERRUPTION)
34
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35
 * STRICT  LIABILITY,  OR  TORT (INCLUDING  NEGLIGENCE  OR  OTHERWISE)
36
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
37
 * OF THE POSSIBILITY OF SUCH DAMAGE.
38
 */
39
40
/**
41
 * @file UriParse.c
42
 * Holds the RFC 3986 %URI parsing implementation.
43
 * NOTE: This source file includes itself twice.
44
 */
45
46
/* What encodings are enabled? */
47
#include <uriparser/UriDefsConfig.h>
48
#if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE))
49
/* Include SELF twice */
50
#  ifdef URI_ENABLE_ANSI
51
#    define URI_PASS_ANSI 1
52
#    include "UriParse.c"
53
#    undef URI_PASS_ANSI
54
#  endif
55
#  ifdef URI_ENABLE_UNICODE
56
#    define URI_PASS_UNICODE 1
57
#    include "UriParse.c"
58
#    undef URI_PASS_UNICODE
59
#  endif
60
#else
61
#  ifdef URI_PASS_ANSI
62
#    include <uriparser/UriDefsAnsi.h>
63
#  else
64
#    include <uriparser/UriDefsUnicode.h>
65
#    include <wchar.h>
66
#  endif
67
68
#  ifndef URI_DOXYGEN
69
#    include <uriparser/Uri.h>
70
#    include <uriparser/UriIp4.h>
71
#    include "UriCommon.h"
72
#    include "UriMemory.h"
73
#    include "UriParseBase.h"
74
#    include "UriSets.h"
75
#  endif
76
77
static const URI_CHAR * URI_FUNC(ParseAuthority)(URI_TYPE(ParserState) * state,
78
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
79
static const URI_CHAR * URI_FUNC(ParseAuthorityTwo)(URI_TYPE(ParserState) * state,
80
        const URI_CHAR * first, const URI_CHAR * afterLast);
81
static const URI_CHAR * URI_FUNC(ParseHexZero)(
82
        const URI_CHAR * first, const URI_CHAR * afterLast);
83
static const URI_CHAR * URI_FUNC(ParseHierPart)(URI_TYPE(ParserState) * state,
84
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
85
static const URI_CHAR * URI_FUNC(ParseIpFutLoop)(URI_TYPE(ParserState) * state,
86
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
87
static const URI_CHAR * URI_FUNC(ParseIpLit2)(URI_TYPE(ParserState) * state,
88
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
89
static const URI_CHAR * URI_FUNC(ParseIPv6address2)(URI_TYPE(ParserState) * state,
90
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
91
static const URI_CHAR * URI_FUNC(ParseMustBeSegmentNzNc)(URI_TYPE(ParserState) * state,
92
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
93
static const URI_CHAR * URI_FUNC(ParseOwnHost)(URI_TYPE(ParserState) * state,
94
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
95
static const URI_CHAR * URI_FUNC(ParseOwnHost2)(URI_TYPE(ParserState) * state,
96
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
97
static const URI_CHAR * URI_FUNC(ParseOwnHostUserInfoNz)(URI_TYPE(ParserState) * state,
98
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
99
static const URI_CHAR * URI_FUNC(ParseOwnPortUserInfo)(URI_TYPE(ParserState) * state,
100
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
101
static const URI_CHAR * URI_FUNC(ParseOwnUserInfo)(URI_TYPE(ParserState) * state,
102
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
103
static const URI_CHAR * URI_FUNC(ParsePartHelperTwo)(URI_TYPE(ParserState) * state,
104
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
105
static const URI_CHAR * URI_FUNC(ParsePathAbsEmpty)(URI_TYPE(ParserState) * state,
106
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
107
static const URI_CHAR * URI_FUNC(ParsePathAbsNoLeadSlash)(URI_TYPE(ParserState) * state,
108
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
109
static const URI_CHAR * URI_FUNC(ParsePathRootless)(URI_TYPE(ParserState) * state,
110
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
111
static const URI_CHAR * URI_FUNC(ParsePchar)(URI_TYPE(ParserState) * state,
112
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
113
static const URI_CHAR * URI_FUNC(ParsePctEncoded)(URI_TYPE(ParserState) * state,
114
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
115
static const URI_CHAR * URI_FUNC(ParsePctSubUnres)(URI_TYPE(ParserState) * state,
116
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
117
static const URI_CHAR * URI_FUNC(ParsePort)(
118
        const URI_CHAR * first, const URI_CHAR * afterLast);
119
static const URI_CHAR * URI_FUNC(ParseQueryFrag)(URI_TYPE(ParserState) * state,
120
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
121
static const URI_CHAR * URI_FUNC(ParseSegment)(URI_TYPE(ParserState) * state,
122
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
123
static const URI_CHAR * URI_FUNC(ParseSegmentNz)(URI_TYPE(ParserState) * state,
124
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
125
static const URI_CHAR * URI_FUNC(ParseSegmentNzNcOrScheme2)(URI_TYPE(ParserState) * state,
126
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
127
static const URI_CHAR * URI_FUNC(ParseUriReference)(URI_TYPE(ParserState) * state,
128
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
129
static const URI_CHAR * URI_FUNC(ParseUriTail)(URI_TYPE(ParserState) * state,
130
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
131
static const URI_CHAR * URI_FUNC(ParseUriTailTwo)(URI_TYPE(ParserState) * state,
132
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
133
static const URI_CHAR * URI_FUNC(ParseZeroMoreSlashSegs)(URI_TYPE(ParserState) * state,
134
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
135
136
static UriBool URI_FUNC(OnExitOwnHost2)(
137
        URI_TYPE(ParserState) * state, const URI_CHAR * first, UriMemoryManager * memory);
138
static UriBool URI_FUNC(OnExitOwnHostUserInfo)(
139
        URI_TYPE(ParserState) * state, const URI_CHAR * first, UriMemoryManager * memory);
140
static UriBool URI_FUNC(OnExitOwnPortUserInfo)(
141
        URI_TYPE(ParserState) * state, const URI_CHAR * first, UriMemoryManager * memory);
142
static UriBool URI_FUNC(OnExitSegmentNzNcOrScheme2)(
143
        URI_TYPE(ParserState) * state, const URI_CHAR * first, UriMemoryManager * memory);
144
static void URI_FUNC(OnExitPartHelperTwo)(URI_TYPE(ParserState) * state);
145
146
static void URI_FUNC(ResetParserStateExceptUri)(URI_TYPE(ParserState) * state);
147
148
static UriBool URI_FUNC(PushPathSegment)(URI_TYPE(ParserState) * state,
149
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory);
150
151
static void URI_FUNC(StopSyntax)(URI_TYPE(ParserState) * state, const URI_CHAR * errorPos,
152
        UriMemoryManager * memory);
153
static void URI_FUNC(StopMalloc)(
154
        URI_TYPE(ParserState) * state, UriMemoryManager * memory);
155
156
static int URI_FUNC(ParseUriExMm)(URI_TYPE(ParserState) * state, const URI_CHAR * first,
157
        const URI_CHAR * afterLast, UriMemoryManager * memory);
158
159
static URI_INLINE void URI_FUNC(StopSyntax)(URI_TYPE(ParserState) * state,
160
2.39k
        const URI_CHAR * errorPos, UriMemoryManager * memory) {
161
2.39k
    URI_FUNC(FreeUriMembersMm)(state->uri, memory);
162
2.39k
    state->errorPos = errorPos;
163
2.39k
    state->errorCode = URI_ERROR_SYNTAX;
164
2.39k
}
UriParse.c:uriStopSyntaxA
Line
Count
Source
160
2.39k
        const URI_CHAR * errorPos, UriMemoryManager * memory) {
161
2.39k
    URI_FUNC(FreeUriMembersMm)(state->uri, memory);
162
2.39k
    state->errorPos = errorPos;
163
2.39k
    state->errorCode = URI_ERROR_SYNTAX;
164
2.39k
}
Unexecuted instantiation: UriParse.c:uriStopSyntaxW
165
166
static URI_INLINE void URI_FUNC(StopMalloc)(
167
0
        URI_TYPE(ParserState) * state, UriMemoryManager * memory) {
168
0
    URI_FUNC(FreeUriMembersMm)(state->uri, memory);
169
0
    state->errorPos = NULL;
170
0
    state->errorCode = URI_ERROR_MALLOC;
171
0
}
Unexecuted instantiation: UriParse.c:uriStopMallocA
Unexecuted instantiation: UriParse.c:uriStopMallocW
172
173
/*
174
 * [authority]-><[>[ipLit2][authorityTwo]
175
 * [authority]->[ownHostUserInfoNz]
176
 * [authority]-><NULL>
177
 */
178
static URI_INLINE const URI_CHAR * URI_FUNC(ParseAuthority)(URI_TYPE(ParserState) * state,
179
3.67k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
180
3.67k
    if (first >= afterLast) {
181
        /* "" regname host */
182
1
        state->uri->hostText.first = URI_FUNC(SafeToPointTo);
183
1
        state->uri->hostText.afterLast = URI_FUNC(SafeToPointTo);
184
1
        return afterLast;
185
1
    }
186
187
3.67k
    switch (*first) {
188
1.33k
    case _UT('['): {
189
1.33k
        const URI_CHAR * const afterIpLit2 =
190
1.33k
                URI_FUNC(ParseIpLit2)(state, first + 1, afterLast, memory);
191
1.33k
        if (afterIpLit2 == NULL) {
192
1.29k
            return NULL;
193
1.29k
        }
194
46
        state->uri->hostText.first = first + 1; /* HOST BEGIN */
195
46
        return URI_FUNC(ParseAuthorityTwo)(state, afterIpLit2, afterLast);
196
1.33k
    }
197
198
28.2k
    case URI_SET_PCHAR(_UT):
199
2.30k
        state->uri->userInfo.first = first; /* USERINFO BEGIN */
200
2.30k
        return URI_FUNC(ParseOwnHostUserInfoNz)(state, first, afterLast, memory);
201
202
36
    default:
203
        /* "" regname host */
204
36
        state->uri->hostText.first = URI_FUNC(SafeToPointTo);
205
36
        state->uri->hostText.afterLast = URI_FUNC(SafeToPointTo);
206
36
        return first;
207
3.67k
    }
208
3.67k
}
UriParse.c:uriParseAuthorityA
Line
Count
Source
179
3.67k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
180
3.67k
    if (first >= afterLast) {
181
        /* "" regname host */
182
1
        state->uri->hostText.first = URI_FUNC(SafeToPointTo);
183
1
        state->uri->hostText.afterLast = URI_FUNC(SafeToPointTo);
184
1
        return afterLast;
185
1
    }
186
187
3.67k
    switch (*first) {
188
1.33k
    case _UT('['): {
189
1.33k
        const URI_CHAR * const afterIpLit2 =
190
1.33k
                URI_FUNC(ParseIpLit2)(state, first + 1, afterLast, memory);
191
1.33k
        if (afterIpLit2 == NULL) {
192
1.29k
            return NULL;
193
1.29k
        }
194
46
        state->uri->hostText.first = first + 1; /* HOST BEGIN */
195
46
        return URI_FUNC(ParseAuthorityTwo)(state, afterIpLit2, afterLast);
196
1.33k
    }
197
198
2.30k
    case URI_SET_PCHAR(_UT):
199
2.30k
        state->uri->userInfo.first = first; /* USERINFO BEGIN */
200
2.30k
        return URI_FUNC(ParseOwnHostUserInfoNz)(state, first, afterLast, memory);
201
202
36
    default:
203
        /* "" regname host */
204
36
        state->uri->hostText.first = URI_FUNC(SafeToPointTo);
205
36
        state->uri->hostText.afterLast = URI_FUNC(SafeToPointTo);
206
36
        return first;
207
3.67k
    }
208
3.67k
}
Unexecuted instantiation: UriParse.c:uriParseAuthorityW
209
210
/*
211
 * [authorityTwo]-><:>[port]
212
 * [authorityTwo]-><NULL>
213
 */
214
static URI_INLINE const URI_CHAR * URI_FUNC(ParseAuthorityTwo)(
215
        URI_TYPE(ParserState) * state, const URI_CHAR * first,
216
114
        const URI_CHAR * afterLast) {
217
114
    if (first >= afterLast) {
218
25
        return afterLast;
219
25
    }
220
221
89
    switch (*first) {
222
62
    case _UT(':'): {
223
62
        const URI_CHAR * const afterPort = URI_FUNC(ParsePort)(first + 1, afterLast);
224
62
        if (afterPort == NULL) {
225
0
            return NULL;
226
0
        }
227
62
        state->uri->portText.first = first + 1; /* PORT BEGIN */
228
62
        state->uri->portText.afterLast = afterPort; /* PORT END */
229
62
        return afterPort;
230
62
    }
231
232
27
    default:
233
27
        return first;
234
89
    }
235
89
}
UriParse.c:uriParseAuthorityTwoA
Line
Count
Source
216
114
        const URI_CHAR * afterLast) {
217
114
    if (first >= afterLast) {
218
25
        return afterLast;
219
25
    }
220
221
89
    switch (*first) {
222
62
    case _UT(':'): {
223
62
        const URI_CHAR * const afterPort = URI_FUNC(ParsePort)(first + 1, afterLast);
224
62
        if (afterPort == NULL) {
225
0
            return NULL;
226
0
        }
227
62
        state->uri->portText.first = first + 1; /* PORT BEGIN */
228
62
        state->uri->portText.afterLast = afterPort; /* PORT END */
229
62
        return afterPort;
230
62
    }
231
232
27
    default:
233
27
        return first;
234
89
    }
235
89
}
Unexecuted instantiation: UriParse.c:uriParseAuthorityTwoW
236
237
/*
238
 * [hexZero]->[HEXDIG][hexZero]
239
 * [hexZero]-><NULL>
240
 */
241
static const URI_CHAR * URI_FUNC(ParseHexZero)(
242
874
        const URI_CHAR * first, const URI_CHAR * afterLast) {
243
5.34k
tail_call:
244
5.34k
    if (first >= afterLast) {
245
200
        return afterLast;
246
200
    }
247
248
5.14k
    switch (*first) {
249
43.9k
    case URI_SET_HEXDIG(_UT):
250
4.46k
        first += 1;
251
4.46k
        goto tail_call;
252
253
674
    default:
254
674
        return first;
255
5.14k
    }
256
5.14k
}
UriParse.c:uriParseHexZeroA
Line
Count
Source
242
874
        const URI_CHAR * first, const URI_CHAR * afterLast) {
243
5.34k
tail_call:
244
5.34k
    if (first >= afterLast) {
245
200
        return afterLast;
246
200
    }
247
248
5.14k
    switch (*first) {
249
4.46k
    case URI_SET_HEXDIG(_UT):
250
4.46k
        first += 1;
251
4.46k
        goto tail_call;
252
253
674
    default:
254
674
        return first;
255
5.14k
    }
256
5.14k
}
Unexecuted instantiation: UriParse.c:uriParseHexZeroW
257
258
/*
259
 * [hierPart]->[pathRootless]
260
 * [hierPart]-></>[partHelperTwo]
261
 * [hierPart]-><NULL>
262
 */
263
static URI_INLINE const URI_CHAR * URI_FUNC(ParseHierPart)(URI_TYPE(ParserState) * state,
264
116
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
265
116
    if (first >= afterLast) {
266
1
        return afterLast;
267
1
    }
268
269
115
    switch (*first) {
270
3.82k
    case URI_SET_PCHAR(_UT):
271
113
        return URI_FUNC(ParsePathRootless)(state, first, afterLast, memory);
272
273
1
    case _UT('/'):
274
1
        return URI_FUNC(ParsePartHelperTwo)(state, first + 1, afterLast, memory);
275
276
1
    default:
277
1
        return first;
278
115
    }
279
115
}
UriParse.c:uriParseHierPartA
Line
Count
Source
264
116
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
265
116
    if (first >= afterLast) {
266
1
        return afterLast;
267
1
    }
268
269
115
    switch (*first) {
270
113
    case URI_SET_PCHAR(_UT):
271
113
        return URI_FUNC(ParsePathRootless)(state, first, afterLast, memory);
272
273
1
    case _UT('/'):
274
1
        return URI_FUNC(ParsePartHelperTwo)(state, first + 1, afterLast, memory);
275
276
1
    default:
277
1
        return first;
278
115
    }
279
115
}
Unexecuted instantiation: UriParse.c:uriParseHierPartW
280
281
/*
282
 * [ipFutLoop]->[subDelims][ipFutStopGo]
283
 * [ipFutLoop]->[unreserved][ipFutStopGo]
284
 * [ipFutLoop]-><:>[ipFutStopGo]
285
 *
286
 * [ipFutStopGo]->[ipFutLoop]
287
 * [ipFutStopGo]-><NULL>
288
 */
289
static const URI_CHAR * URI_FUNC(ParseIpFutLoop)(URI_TYPE(ParserState) * state,
290
657
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
291
657
    const URI_CHAR * const originalFirst = first;
292
293
48.1k
    while (first < afterLast) {
294
47.5k
        switch (*first) {
295
198
        case _UT(':'):
296
17.2k
        case URI_SET_SUB_DELIMS(_UT):
297
1.70M
        case URI_SET_UNRESERVED(_UT):
298
47.5k
            first += 1;
299
47.5k
            break;
300
301
21
        default:
302
21
            goto done_looping;
303
21
            break;
304
47.5k
        }
305
47.5k
    }
306
307
657
done_looping:
308
657
    if (first == originalFirst) {
309
2
        URI_FUNC(StopSyntax)(state, first, memory);
310
2
        return NULL;
311
2
    }
312
313
655
    return first;
314
657
}
UriParse.c:uriParseIpFutLoopA
Line
Count
Source
290
657
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
291
657
    const URI_CHAR * const originalFirst = first;
292
293
48.1k
    while (first < afterLast) {
294
47.5k
        switch (*first) {
295
198
        case _UT(':'):
296
17.2k
        case URI_SET_SUB_DELIMS(_UT):
297
47.5k
        case URI_SET_UNRESERVED(_UT):
298
47.5k
            first += 1;
299
47.5k
            break;
300
301
21
        default:
302
21
            goto done_looping;
303
21
            break;
304
47.5k
        }
305
47.5k
    }
306
307
657
done_looping:
308
657
    if (first == originalFirst) {
309
2
        URI_FUNC(StopSyntax)(state, first, memory);
310
2
        return NULL;
311
2
    }
312
313
655
    return first;
314
657
}
Unexecuted instantiation: UriParse.c:uriParseIpFutLoopW
315
316
/*
317
 * [ipFuture]-><v>[HEXDIG][hexZero]<.>[ipFutLoop]
318
 */
319
static const URI_CHAR * URI_FUNC(ParseIpFuture)(URI_TYPE(ParserState) * state,
320
877
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
321
877
    if (first >= afterLast) {
322
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
323
0
        return NULL;
324
0
    }
325
326
    /*
327
    First character has already been
328
    checked before entering this rule.
329
330
    switch (*first) {
331
    case _UT('v'):
332
    case _UT('V'):
333
    */
334
877
    if (afterLast - first < 2) {
335
2
        URI_FUNC(StopSyntax)(state, afterLast, memory);
336
2
        return NULL;
337
2
    }
338
339
875
    switch (first[1]) {
340
10.7k
    case URI_SET_HEXDIG(_UT): {
341
10.7k
        const URI_CHAR * afterIpFutLoop;
342
10.7k
        const URI_CHAR * const afterHexZero =
343
10.7k
                URI_FUNC(ParseHexZero)(first + 2, afterLast);
344
10.7k
        if (afterHexZero == NULL) {
345
0
            return NULL;
346
0
        }
347
874
        if (afterHexZero >= afterLast) {
348
200
            URI_FUNC(StopSyntax)(state, afterLast, memory);
349
200
            return NULL;
350
200
        }
351
674
        if (*afterHexZero != _UT('.')) {
352
17
            URI_FUNC(StopSyntax)(state, afterHexZero, memory);
353
17
            return NULL;
354
17
        }
355
657
        state->uri->hostText.first = first; /* HOST BEGIN */
356
657
        state->uri->hostData.ipFuture.first = first; /* IPFUTURE BEGIN */
357
657
        afterIpFutLoop =
358
657
                URI_FUNC(ParseIpFutLoop)(state, afterHexZero + 1, afterLast, memory);
359
657
        if (afterIpFutLoop == NULL) {
360
2
            return NULL;
361
2
        }
362
655
        state->uri->hostText.afterLast = afterIpFutLoop; /* HOST END */
363
655
        state->uri->hostData.ipFuture.afterLast = afterIpFutLoop; /* IPFUTURE END */
364
655
        return afterIpFutLoop;
365
657
    }
366
367
1
    default:
368
1
        URI_FUNC(StopSyntax)(state, first + 1, memory);
369
1
        return NULL;
370
875
    }
371
372
    /*
373
    default:
374
            URI_FUNC(StopSyntax)(state, first, memory);
375
            return NULL;
376
    }
377
    */
378
875
}
UriParse.c:uriParseIpFutureA
Line
Count
Source
320
877
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
321
877
    if (first >= afterLast) {
322
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
323
0
        return NULL;
324
0
    }
325
326
    /*
327
    First character has already been
328
    checked before entering this rule.
329
330
    switch (*first) {
331
    case _UT('v'):
332
    case _UT('V'):
333
    */
334
877
    if (afterLast - first < 2) {
335
2
        URI_FUNC(StopSyntax)(state, afterLast, memory);
336
2
        return NULL;
337
2
    }
338
339
875
    switch (first[1]) {
340
10.7k
    case URI_SET_HEXDIG(_UT): {
341
10.7k
        const URI_CHAR * afterIpFutLoop;
342
10.7k
        const URI_CHAR * const afterHexZero =
343
10.7k
                URI_FUNC(ParseHexZero)(first + 2, afterLast);
344
10.7k
        if (afterHexZero == NULL) {
345
0
            return NULL;
346
0
        }
347
874
        if (afterHexZero >= afterLast) {
348
200
            URI_FUNC(StopSyntax)(state, afterLast, memory);
349
200
            return NULL;
350
200
        }
351
674
        if (*afterHexZero != _UT('.')) {
352
17
            URI_FUNC(StopSyntax)(state, afterHexZero, memory);
353
17
            return NULL;
354
17
        }
355
657
        state->uri->hostText.first = first; /* HOST BEGIN */
356
657
        state->uri->hostData.ipFuture.first = first; /* IPFUTURE BEGIN */
357
657
        afterIpFutLoop =
358
657
                URI_FUNC(ParseIpFutLoop)(state, afterHexZero + 1, afterLast, memory);
359
657
        if (afterIpFutLoop == NULL) {
360
2
            return NULL;
361
2
        }
362
655
        state->uri->hostText.afterLast = afterIpFutLoop; /* HOST END */
363
655
        state->uri->hostData.ipFuture.afterLast = afterIpFutLoop; /* IPFUTURE END */
364
655
        return afterIpFutLoop;
365
657
    }
366
367
1
    default:
368
1
        URI_FUNC(StopSyntax)(state, first + 1, memory);
369
1
        return NULL;
370
875
    }
371
372
    /*
373
    default:
374
            URI_FUNC(StopSyntax)(state, first, memory);
375
            return NULL;
376
    }
377
    */
378
875
}
Unexecuted instantiation: UriParse.c:uriParseIpFutureW
379
380
/*
381
 * [ipLit2]->[ipFuture]<]>
382
 * [ipLit2]->[IPv6address2]
383
 */
384
static URI_INLINE const URI_CHAR * URI_FUNC(ParseIpLit2)(URI_TYPE(ParserState) * state,
385
1.37k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
386
1.37k
    if (first >= afterLast) {
387
2
        URI_FUNC(StopSyntax)(state, afterLast, memory);
388
2
        return NULL;
389
2
    }
390
391
1.37k
    switch (*first) {
392
    /* The leading "v" of IPvFuture is case-insensitive. */
393
442
    case _UT('v'):
394
877
    case _UT('V'): {
395
877
        const URI_CHAR * const afterIpFuture =
396
877
                URI_FUNC(ParseIpFuture)(state, first, afterLast, memory);
397
877
        if (afterIpFuture == NULL) {
398
222
            return NULL;
399
222
        }
400
655
        if (afterIpFuture >= afterLast) {
401
635
            URI_FUNC(StopSyntax)(state, afterLast, memory);
402
635
            return NULL;
403
635
        }
404
20
        if (*afterIpFuture != _UT(']')) {
405
19
            URI_FUNC(StopSyntax)(state, afterIpFuture, memory);
406
19
            return NULL;
407
19
        }
408
1
        return afterIpFuture + 1;
409
20
    }
410
411
265
    case _UT(':'):
412
266
    case _UT(']'):
413
8.32k
    case URI_SET_HEXDIG(_UT):
414
8.32k
        state->uri->hostData.ip6 = memory->malloc(
415
8.32k
                memory, 1 * sizeof(UriIp6)); /* Freed when stopping on parse error */
416
8.32k
        if (state->uri->hostData.ip6 == NULL) {
417
0
            URI_FUNC(StopMalloc)(state, memory);
418
0
            return NULL;
419
0
        }
420
492
        return URI_FUNC(ParseIPv6address2)(state, first, afterLast, memory);
421
422
1
    default:
423
1
        URI_FUNC(StopSyntax)(state, first, memory);
424
1
        return NULL;
425
1.37k
    }
426
1.37k
}
UriParse.c:uriParseIpLit2A
Line
Count
Source
385
1.37k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
386
1.37k
    if (first >= afterLast) {
387
2
        URI_FUNC(StopSyntax)(state, afterLast, memory);
388
2
        return NULL;
389
2
    }
390
391
1.37k
    switch (*first) {
392
    /* The leading "v" of IPvFuture is case-insensitive. */
393
442
    case _UT('v'):
394
877
    case _UT('V'): {
395
877
        const URI_CHAR * const afterIpFuture =
396
877
                URI_FUNC(ParseIpFuture)(state, first, afterLast, memory);
397
877
        if (afterIpFuture == NULL) {
398
222
            return NULL;
399
222
        }
400
655
        if (afterIpFuture >= afterLast) {
401
635
            URI_FUNC(StopSyntax)(state, afterLast, memory);
402
635
            return NULL;
403
635
        }
404
20
        if (*afterIpFuture != _UT(']')) {
405
19
            URI_FUNC(StopSyntax)(state, afterIpFuture, memory);
406
19
            return NULL;
407
19
        }
408
1
        return afterIpFuture + 1;
409
20
    }
410
411
265
    case _UT(':'):
412
266
    case _UT(']'):
413
8.32k
    case URI_SET_HEXDIG(_UT):
414
8.32k
        state->uri->hostData.ip6 = memory->malloc(
415
8.32k
                memory, 1 * sizeof(UriIp6)); /* Freed when stopping on parse error */
416
8.32k
        if (state->uri->hostData.ip6 == NULL) {
417
0
            URI_FUNC(StopMalloc)(state, memory);
418
0
            return NULL;
419
0
        }
420
492
        return URI_FUNC(ParseIPv6address2)(state, first, afterLast, memory);
421
422
1
    default:
423
1
        URI_FUNC(StopSyntax)(state, first, memory);
424
        return NULL;
425
1.37k
    }
426
1.37k
}
Unexecuted instantiation: UriParse.c:uriParseIpLit2W
427
428
/*
429
 * [IPv6address2]->..<]>
430
 */
431
static const URI_CHAR * URI_FUNC(ParseIPv6address2)(URI_TYPE(ParserState) * state,
432
492
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
433
492
    int zipperEver = 0;
434
492
    int quadsDone = 0;
435
492
    int digitCount = 0;
436
492
    unsigned char digitHistory[4];
437
492
    int ip4OctetsDone = 0;
438
439
492
    unsigned char quadsAfterZipper[14];
440
492
    int quadsAfterZipperCount = 0;
441
442
631
    for (;;) {
443
631
        if (first >= afterLast) {
444
0
            URI_FUNC(StopSyntax)(state, afterLast, memory);
445
0
            return NULL;
446
0
        }
447
448
        /* Inside IPv4 part? */
449
631
        if (ip4OctetsDone > 0) {
450
            /* Eat rest of IPv4 address */
451
777
            for (;;) {
452
777
                switch (*first) {
453
3.48k
                case URI_SET_DIGIT(_UT):
454
3.48k
                    if (digitCount == 4) {
455
8
                        URI_FUNC(StopSyntax)(state, first, memory);
456
8
                        return NULL;
457
8
                    }
458
557
                    digitHistory[digitCount++] = (unsigned char)(9 + *first - _UT('9'));
459
557
                    break;
460
461
167
                case _UT('.'):
462
167
                    if ((ip4OctetsDone == 4) /* NOTE! */
463
165
                            || (digitCount == 0) || (digitCount == 4)) {
464
                        /* Invalid digit or octet count */
465
5
                        URI_FUNC(StopSyntax)(state, first, memory);
466
5
                        return NULL;
467
162
                    } else if ((digitCount > 1) && (digitHistory[0] == 0)) {
468
                        /* Leading zero */
469
1
                        URI_FUNC(StopSyntax)(state, first - digitCount, memory);
470
1
                        return NULL;
471
161
                    } else if ((digitCount == 3)
472
59
                               && (100 * digitHistory[0] + 10 * digitHistory[1]
473
59
                                               + digitHistory[2]
474
59
                                       > 255)) {
475
                        /* Octet value too large */
476
10
                        if (digitHistory[0] > 2) {
477
3
                            URI_FUNC(StopSyntax)(state, first - 3, memory);
478
7
                        } else if (digitHistory[1] > 5) {
479
5
                            URI_FUNC(StopSyntax)(state, first - 2, memory);
480
5
                        } else {
481
2
                            URI_FUNC(StopSyntax)(state, first - 1, memory);
482
2
                        }
483
10
                        return NULL;
484
10
                    }
485
486
                    /* Copy IPv4 octet */
487
151
                    state->uri->hostData.ip6->data[16 - 4 + ip4OctetsDone] =
488
151
                            uriGetOctetValue(digitHistory, digitCount);
489
151
                    digitCount = 0;
490
151
                    ip4OctetsDone++;
491
151
                    break;
492
493
27
                case _UT(']'):
494
27
                    if ((ip4OctetsDone != 3) /* NOTE! */
495
24
                            || (digitCount == 0) || (digitCount == 4)) {
496
                        /* Invalid digit or octet count */
497
5
                        URI_FUNC(StopSyntax)(state, first, memory);
498
5
                        return NULL;
499
22
                    } else if ((digitCount > 1) && (digitHistory[0] == 0)) {
500
                        /* Leading zero */
501
1
                        URI_FUNC(StopSyntax)(state, first - digitCount, memory);
502
1
                        return NULL;
503
21
                    } else if ((digitCount == 3)
504
17
                               && (100 * digitHistory[0] + 10 * digitHistory[1]
505
17
                                               + digitHistory[2]
506
17
                                       > 255)) {
507
                        /* Octet value too large */
508
8
                        if (digitHistory[0] > 2) {
509
5
                            URI_FUNC(StopSyntax)(state, first - 3, memory);
510
5
                        } else if (digitHistory[1] > 5) {
511
2
                            URI_FUNC(StopSyntax)(state, first - 2, memory);
512
2
                        } else {
513
1
                            URI_FUNC(StopSyntax)(state, first - 1, memory);
514
1
                        }
515
8
                        return NULL;
516
8
                    }
517
518
13
                    state->uri->hostText.afterLast = first; /* HOST END */
519
520
                    /* Copy missing quads right before IPv4 */
521
13
                    memcpy(state->uri->hostData.ip6->data + 16 - 4
522
13
                                    - 2 * quadsAfterZipperCount,
523
13
                            quadsAfterZipper, 2 * quadsAfterZipperCount);
524
525
                    /* Copy last IPv4 octet */
526
13
                    state->uri->hostData.ip6->data[16 - 4 + 3] =
527
13
                            uriGetOctetValue(digitHistory, digitCount);
528
529
13
                    return first + 1;
530
531
18
                default:
532
18
                    URI_FUNC(StopSyntax)(state, first, memory);
533
18
                    return NULL;
534
777
                }
535
708
                first++;
536
537
708
                if (first >= afterLast) {
538
70
                    URI_FUNC(StopSyntax)(state, afterLast, memory);
539
70
                    return NULL;
540
70
                }
541
708
            }
542
492
        } else {
543
            /* Eat while no dot in sight */
544
492
            int letterAmong = 0;
545
492
            int walking = 1;
546
3.20k
            do {
547
3.20k
                switch (*first) {
548
1.58k
                case URI_SET_HEX_LETTER_LOWER(_UT):
549
1.58k
                    letterAmong = 1;
550
1.58k
                    if (digitCount == 4) {
551
7
                        URI_FUNC(StopSyntax)(state, first, memory);
552
7
                        return NULL;
553
7
                    }
554
485
                    digitHistory[digitCount] = (unsigned char)(15 + *first - _UT('f'));
555
485
                    digitCount++;
556
485
                    break;
557
558
1.61k
                case URI_SET_HEX_LETTER_UPPER(_UT):
559
1.61k
                    letterAmong = 1;
560
1.61k
                    if (digitCount == 4) {
561
9
                        URI_FUNC(StopSyntax)(state, first, memory);
562
9
                        return NULL;
563
9
                    }
564
485
                    digitHistory[digitCount] = (unsigned char)(15 + *first - _UT('F'));
565
485
                    digitCount++;
566
485
                    break;
567
568
6.76k
                case URI_SET_DIGIT(_UT):
569
6.76k
                    if (digitCount == 4) {
570
23
                        URI_FUNC(StopSyntax)(state, first, memory);
571
23
                        return NULL;
572
23
                    }
573
1.17k
                    digitHistory[digitCount] = (unsigned char)(9 + *first - _UT('9'));
574
1.17k
                    digitCount++;
575
1.17k
                    break;
576
577
753
                case _UT(':'): {
578
753
                    int setZipper = 0;
579
580
753
                    if (digitCount > 0) {
581
488
                        if (zipperEver) {
582
33
                            uriWriteQuadToDoubleByte(digitHistory, digitCount,
583
33
                                    quadsAfterZipper + 2 * quadsAfterZipperCount);
584
33
                            quadsAfterZipperCount++;
585
455
                        } else {
586
455
                            uriWriteQuadToDoubleByte(digitHistory, digitCount,
587
455
                                    state->uri->hostData.ip6->data + 2 * quadsDone);
588
455
                        }
589
488
                        quadsDone++;
590
488
                        digitCount = 0;
591
488
                    }
592
753
                    letterAmong = 0;
593
594
                    /* Too many quads? */
595
753
                    if (quadsDone >= 8 - zipperEver) {
596
6
                        URI_FUNC(StopSyntax)(state, first, memory);
597
6
                        return NULL;
598
6
                    }
599
600
                    /* "::"? */
601
747
                    if (afterLast - first < 2) {
602
22
                        URI_FUNC(StopSyntax)(state, afterLast, memory);
603
22
                        return NULL;
604
22
                    }
605
725
                    if (first[1] == _UT(':')) {
606
267
                        const int resetOffset = 2 * (quadsDone + (digitCount > 0));
607
608
267
                        first++;
609
267
                        if (zipperEver) {
610
1
                            URI_FUNC(StopSyntax)(state, first, memory);
611
1
                            return NULL; /* "::.+::" */
612
1
                        }
613
614
                        /* Zero everything after zipper */
615
266
                        memset(state->uri->hostData.ip6->data + resetOffset, 0,
616
266
                                16 - resetOffset);
617
266
                        setZipper = 1;
618
619
                        /* ":::+"? */
620
266
                        if (afterLast - first < 2) {
621
1
                            URI_FUNC(StopSyntax)(state, afterLast, memory);
622
1
                            return NULL; /* No ']' yet */
623
1
                        }
624
265
                        if (first[1] == _UT(':')) {
625
2
                            URI_FUNC(StopSyntax)(state, first + 1, memory);
626
2
                            return NULL; /* ":::+ "*/
627
2
                        }
628
458
                    } else if (quadsDone == 0 || first[1] == _UT(']')) {
629
                        /* Single leading or trailing ":" */
630
13
                        URI_FUNC(StopSyntax)(state, first, memory);
631
13
                        return NULL;
632
13
                    }
633
634
708
                    if (setZipper) {
635
263
                        zipperEver = 1;
636
263
                    }
637
708
                } break;
638
639
177
                case _UT('.'):
640
177
                    if ((quadsDone + zipperEver > 6) /* NOTE */
641
176
                            || (!zipperEver && (quadsDone < 6)) || letterAmong
642
170
                            || (digitCount == 0) || (digitCount == 4)) {
643
                        /* Invalid octet before */
644
14
                        URI_FUNC(StopSyntax)(state, first, memory);
645
14
                        return NULL;
646
163
                    } else if ((digitCount > 1) && (digitHistory[0] == 0)) {
647
                        /* Leading zero */
648
1
                        URI_FUNC(StopSyntax)(state, first - digitCount, memory);
649
1
                        return NULL;
650
162
                    } else if ((digitCount == 3)
651
22
                               && (100 * digitHistory[0] + 10 * digitHistory[1]
652
22
                                               + digitHistory[2]
653
22
                                       > 255)) {
654
                        /* Octet value too large */
655
10
                        if (digitHistory[0] > 2) {
656
5
                            URI_FUNC(StopSyntax)(state, first - 3, memory);
657
5
                        } else if (digitHistory[1] > 5) {
658
4
                            URI_FUNC(StopSyntax)(state, first - 2, memory);
659
4
                        } else {
660
1
                            URI_FUNC(StopSyntax)(state, first - 1, memory);
661
1
                        }
662
10
                        return NULL;
663
10
                    }
664
665
                    /* Copy first IPv4 octet */
666
152
                    state->uri->hostData.ip6->data[16 - 4] =
667
152
                            uriGetOctetValue(digitHistory, digitCount);
668
152
                    digitCount = 0;
669
670
                    /* Switch over to IPv4 loop */
671
152
                    ip4OctetsDone = 1;
672
152
                    walking = 0;
673
152
                    break;
674
675
71
                case _UT(']'):
676
                    /* Too little quads? */
677
71
                    if (!zipperEver && !((quadsDone == 7) && (digitCount > 0))) {
678
5
                        URI_FUNC(StopSyntax)(state, first, memory);
679
5
                        return NULL;
680
5
                    }
681
682
66
                    if (digitCount > 0) {
683
10
                        if (zipperEver) {
684
                            /* Too many quads? */
685
8
                            if (quadsDone >= 7) {
686
1
                                URI_FUNC(StopSyntax)(state, first, memory);
687
1
                                return NULL;
688
1
                            }
689
7
                            uriWriteQuadToDoubleByte(digitHistory, digitCount,
690
7
                                    quadsAfterZipper + 2 * quadsAfterZipperCount);
691
7
                            quadsAfterZipperCount++;
692
7
                        } else {
693
2
                            uriWriteQuadToDoubleByte(digitHistory, digitCount,
694
2
                                    state->uri->hostData.ip6->data + 2 * quadsDone);
695
2
                        }
696
                        /*
697
                        quadsDone++;
698
                        digitCount = 0;
699
                        */
700
10
                    }
701
702
                    /* Copy missing quads to the end */
703
65
                    memcpy(state->uri->hostData.ip6->data + 16
704
65
                                    - 2 * quadsAfterZipperCount,
705
65
                            quadsAfterZipper, 2 * quadsAfterZipperCount);
706
707
65
                    state->uri->hostText.afterLast = first; /* HOST END */
708
65
                    return first + 1; /* Fine */
709
710
26
                default:
711
26
                    URI_FUNC(StopSyntax)(state, first, memory);
712
26
                    return NULL;
713
3.20k
                }
714
3.00k
                first++;
715
716
3.00k
                if (first >= afterLast) {
717
147
                    URI_FUNC(StopSyntax)(state, afterLast, memory);
718
147
                    return NULL; /* No ']' yet */
719
147
                }
720
3.00k
            } while (walking);
721
492
        }
722
631
    }
723
492
}
UriParse.c:uriParseIPv6address2A
Line
Count
Source
432
492
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
433
492
    int zipperEver = 0;
434
492
    int quadsDone = 0;
435
492
    int digitCount = 0;
436
492
    unsigned char digitHistory[4];
437
492
    int ip4OctetsDone = 0;
438
439
492
    unsigned char quadsAfterZipper[14];
440
492
    int quadsAfterZipperCount = 0;
441
442
631
    for (;;) {
443
631
        if (first >= afterLast) {
444
0
            URI_FUNC(StopSyntax)(state, afterLast, memory);
445
0
            return NULL;
446
0
        }
447
448
        /* Inside IPv4 part? */
449
631
        if (ip4OctetsDone > 0) {
450
            /* Eat rest of IPv4 address */
451
777
            for (;;) {
452
777
                switch (*first) {
453
3.48k
                case URI_SET_DIGIT(_UT):
454
3.48k
                    if (digitCount == 4) {
455
8
                        URI_FUNC(StopSyntax)(state, first, memory);
456
8
                        return NULL;
457
8
                    }
458
557
                    digitHistory[digitCount++] = (unsigned char)(9 + *first - _UT('9'));
459
557
                    break;
460
461
167
                case _UT('.'):
462
167
                    if ((ip4OctetsDone == 4) /* NOTE! */
463
165
                            || (digitCount == 0) || (digitCount == 4)) {
464
                        /* Invalid digit or octet count */
465
5
                        URI_FUNC(StopSyntax)(state, first, memory);
466
5
                        return NULL;
467
162
                    } else if ((digitCount > 1) && (digitHistory[0] == 0)) {
468
                        /* Leading zero */
469
1
                        URI_FUNC(StopSyntax)(state, first - digitCount, memory);
470
1
                        return NULL;
471
161
                    } else if ((digitCount == 3)
472
59
                               && (100 * digitHistory[0] + 10 * digitHistory[1]
473
59
                                               + digitHistory[2]
474
59
                                       > 255)) {
475
                        /* Octet value too large */
476
10
                        if (digitHistory[0] > 2) {
477
3
                            URI_FUNC(StopSyntax)(state, first - 3, memory);
478
7
                        } else if (digitHistory[1] > 5) {
479
5
                            URI_FUNC(StopSyntax)(state, first - 2, memory);
480
5
                        } else {
481
2
                            URI_FUNC(StopSyntax)(state, first - 1, memory);
482
2
                        }
483
10
                        return NULL;
484
10
                    }
485
486
                    /* Copy IPv4 octet */
487
151
                    state->uri->hostData.ip6->data[16 - 4 + ip4OctetsDone] =
488
151
                            uriGetOctetValue(digitHistory, digitCount);
489
151
                    digitCount = 0;
490
151
                    ip4OctetsDone++;
491
151
                    break;
492
493
27
                case _UT(']'):
494
27
                    if ((ip4OctetsDone != 3) /* NOTE! */
495
24
                            || (digitCount == 0) || (digitCount == 4)) {
496
                        /* Invalid digit or octet count */
497
5
                        URI_FUNC(StopSyntax)(state, first, memory);
498
5
                        return NULL;
499
22
                    } else if ((digitCount > 1) && (digitHistory[0] == 0)) {
500
                        /* Leading zero */
501
1
                        URI_FUNC(StopSyntax)(state, first - digitCount, memory);
502
1
                        return NULL;
503
21
                    } else if ((digitCount == 3)
504
17
                               && (100 * digitHistory[0] + 10 * digitHistory[1]
505
17
                                               + digitHistory[2]
506
17
                                       > 255)) {
507
                        /* Octet value too large */
508
8
                        if (digitHistory[0] > 2) {
509
5
                            URI_FUNC(StopSyntax)(state, first - 3, memory);
510
5
                        } else if (digitHistory[1] > 5) {
511
2
                            URI_FUNC(StopSyntax)(state, first - 2, memory);
512
2
                        } else {
513
1
                            URI_FUNC(StopSyntax)(state, first - 1, memory);
514
1
                        }
515
8
                        return NULL;
516
8
                    }
517
518
13
                    state->uri->hostText.afterLast = first; /* HOST END */
519
520
                    /* Copy missing quads right before IPv4 */
521
13
                    memcpy(state->uri->hostData.ip6->data + 16 - 4
522
13
                                    - 2 * quadsAfterZipperCount,
523
13
                            quadsAfterZipper, 2 * quadsAfterZipperCount);
524
525
                    /* Copy last IPv4 octet */
526
13
                    state->uri->hostData.ip6->data[16 - 4 + 3] =
527
13
                            uriGetOctetValue(digitHistory, digitCount);
528
529
13
                    return first + 1;
530
531
18
                default:
532
18
                    URI_FUNC(StopSyntax)(state, first, memory);
533
18
                    return NULL;
534
777
                }
535
708
                first++;
536
537
708
                if (first >= afterLast) {
538
70
                    URI_FUNC(StopSyntax)(state, afterLast, memory);
539
70
                    return NULL;
540
70
                }
541
708
            }
542
492
        } else {
543
            /* Eat while no dot in sight */
544
492
            int letterAmong = 0;
545
492
            int walking = 1;
546
3.20k
            do {
547
3.20k
                switch (*first) {
548
1.58k
                case URI_SET_HEX_LETTER_LOWER(_UT):
549
1.58k
                    letterAmong = 1;
550
1.58k
                    if (digitCount == 4) {
551
7
                        URI_FUNC(StopSyntax)(state, first, memory);
552
7
                        return NULL;
553
7
                    }
554
485
                    digitHistory[digitCount] = (unsigned char)(15 + *first - _UT('f'));
555
485
                    digitCount++;
556
485
                    break;
557
558
1.61k
                case URI_SET_HEX_LETTER_UPPER(_UT):
559
1.61k
                    letterAmong = 1;
560
1.61k
                    if (digitCount == 4) {
561
9
                        URI_FUNC(StopSyntax)(state, first, memory);
562
9
                        return NULL;
563
9
                    }
564
485
                    digitHistory[digitCount] = (unsigned char)(15 + *first - _UT('F'));
565
485
                    digitCount++;
566
485
                    break;
567
568
6.76k
                case URI_SET_DIGIT(_UT):
569
6.76k
                    if (digitCount == 4) {
570
23
                        URI_FUNC(StopSyntax)(state, first, memory);
571
23
                        return NULL;
572
23
                    }
573
1.17k
                    digitHistory[digitCount] = (unsigned char)(9 + *first - _UT('9'));
574
1.17k
                    digitCount++;
575
1.17k
                    break;
576
577
753
                case _UT(':'): {
578
753
                    int setZipper = 0;
579
580
753
                    if (digitCount > 0) {
581
488
                        if (zipperEver) {
582
33
                            uriWriteQuadToDoubleByte(digitHistory, digitCount,
583
33
                                    quadsAfterZipper + 2 * quadsAfterZipperCount);
584
33
                            quadsAfterZipperCount++;
585
455
                        } else {
586
455
                            uriWriteQuadToDoubleByte(digitHistory, digitCount,
587
455
                                    state->uri->hostData.ip6->data + 2 * quadsDone);
588
455
                        }
589
488
                        quadsDone++;
590
488
                        digitCount = 0;
591
488
                    }
592
753
                    letterAmong = 0;
593
594
                    /* Too many quads? */
595
753
                    if (quadsDone >= 8 - zipperEver) {
596
6
                        URI_FUNC(StopSyntax)(state, first, memory);
597
6
                        return NULL;
598
6
                    }
599
600
                    /* "::"? */
601
747
                    if (afterLast - first < 2) {
602
22
                        URI_FUNC(StopSyntax)(state, afterLast, memory);
603
22
                        return NULL;
604
22
                    }
605
725
                    if (first[1] == _UT(':')) {
606
267
                        const int resetOffset = 2 * (quadsDone + (digitCount > 0));
607
608
267
                        first++;
609
267
                        if (zipperEver) {
610
1
                            URI_FUNC(StopSyntax)(state, first, memory);
611
1
                            return NULL; /* "::.+::" */
612
1
                        }
613
614
                        /* Zero everything after zipper */
615
266
                        memset(state->uri->hostData.ip6->data + resetOffset, 0,
616
266
                                16 - resetOffset);
617
266
                        setZipper = 1;
618
619
                        /* ":::+"? */
620
266
                        if (afterLast - first < 2) {
621
1
                            URI_FUNC(StopSyntax)(state, afterLast, memory);
622
1
                            return NULL; /* No ']' yet */
623
1
                        }
624
265
                        if (first[1] == _UT(':')) {
625
2
                            URI_FUNC(StopSyntax)(state, first + 1, memory);
626
2
                            return NULL; /* ":::+ "*/
627
2
                        }
628
458
                    } else if (quadsDone == 0 || first[1] == _UT(']')) {
629
                        /* Single leading or trailing ":" */
630
13
                        URI_FUNC(StopSyntax)(state, first, memory);
631
13
                        return NULL;
632
13
                    }
633
634
708
                    if (setZipper) {
635
263
                        zipperEver = 1;
636
263
                    }
637
708
                } break;
638
639
177
                case _UT('.'):
640
177
                    if ((quadsDone + zipperEver > 6) /* NOTE */
641
176
                            || (!zipperEver && (quadsDone < 6)) || letterAmong
642
170
                            || (digitCount == 0) || (digitCount == 4)) {
643
                        /* Invalid octet before */
644
14
                        URI_FUNC(StopSyntax)(state, first, memory);
645
14
                        return NULL;
646
163
                    } else if ((digitCount > 1) && (digitHistory[0] == 0)) {
647
                        /* Leading zero */
648
1
                        URI_FUNC(StopSyntax)(state, first - digitCount, memory);
649
1
                        return NULL;
650
162
                    } else if ((digitCount == 3)
651
22
                               && (100 * digitHistory[0] + 10 * digitHistory[1]
652
22
                                               + digitHistory[2]
653
22
                                       > 255)) {
654
                        /* Octet value too large */
655
10
                        if (digitHistory[0] > 2) {
656
5
                            URI_FUNC(StopSyntax)(state, first - 3, memory);
657
5
                        } else if (digitHistory[1] > 5) {
658
4
                            URI_FUNC(StopSyntax)(state, first - 2, memory);
659
4
                        } else {
660
1
                            URI_FUNC(StopSyntax)(state, first - 1, memory);
661
1
                        }
662
10
                        return NULL;
663
10
                    }
664
665
                    /* Copy first IPv4 octet */
666
152
                    state->uri->hostData.ip6->data[16 - 4] =
667
152
                            uriGetOctetValue(digitHistory, digitCount);
668
152
                    digitCount = 0;
669
670
                    /* Switch over to IPv4 loop */
671
152
                    ip4OctetsDone = 1;
672
152
                    walking = 0;
673
152
                    break;
674
675
71
                case _UT(']'):
676
                    /* Too little quads? */
677
71
                    if (!zipperEver && !((quadsDone == 7) && (digitCount > 0))) {
678
5
                        URI_FUNC(StopSyntax)(state, first, memory);
679
5
                        return NULL;
680
5
                    }
681
682
66
                    if (digitCount > 0) {
683
10
                        if (zipperEver) {
684
                            /* Too many quads? */
685
8
                            if (quadsDone >= 7) {
686
1
                                URI_FUNC(StopSyntax)(state, first, memory);
687
1
                                return NULL;
688
1
                            }
689
7
                            uriWriteQuadToDoubleByte(digitHistory, digitCount,
690
7
                                    quadsAfterZipper + 2 * quadsAfterZipperCount);
691
7
                            quadsAfterZipperCount++;
692
7
                        } else {
693
2
                            uriWriteQuadToDoubleByte(digitHistory, digitCount,
694
2
                                    state->uri->hostData.ip6->data + 2 * quadsDone);
695
2
                        }
696
                        /*
697
                        quadsDone++;
698
                        digitCount = 0;
699
                        */
700
10
                    }
701
702
                    /* Copy missing quads to the end */
703
65
                    memcpy(state->uri->hostData.ip6->data + 16
704
65
                                    - 2 * quadsAfterZipperCount,
705
65
                            quadsAfterZipper, 2 * quadsAfterZipperCount);
706
707
65
                    state->uri->hostText.afterLast = first; /* HOST END */
708
65
                    return first + 1; /* Fine */
709
710
26
                default:
711
26
                    URI_FUNC(StopSyntax)(state, first, memory);
712
26
                    return NULL;
713
3.20k
                }
714
3.00k
                first++;
715
716
3.00k
                if (first >= afterLast) {
717
147
                    URI_FUNC(StopSyntax)(state, afterLast, memory);
718
147
                    return NULL; /* No ']' yet */
719
147
                }
720
3.00k
            } while (walking);
721
492
        }
722
631
    }
723
492
}
Unexecuted instantiation: UriParse.c:uriParseIPv6address2W
724
725
/*
726
 * [mustBeSegmentNzNc]->[pctEncoded][mustBeSegmentNzNc]
727
 * [mustBeSegmentNzNc]->[subDelims][mustBeSegmentNzNc]
728
 * [mustBeSegmentNzNc]->[unreserved][mustBeSegmentNzNc]
729
 * [mustBeSegmentNzNc]->[uriTail] // can take <NULL>
730
 * [mustBeSegmentNzNc]-></>[segment][zeroMoreSlashSegs][uriTail]
731
 * [mustBeSegmentNzNc]-><@>[mustBeSegmentNzNc]
732
 */
733
static const URI_CHAR * URI_FUNC(ParseMustBeSegmentNzNc)(URI_TYPE(ParserState) * state,
734
1.18k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
735
40.2k
tail_call:
736
40.2k
    if (first >= afterLast) {
737
858
        if (!URI_FUNC(PushPathSegment)(
738
858
                    state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
739
0
            URI_FUNC(StopMalloc)(state, memory);
740
0
            return NULL;
741
0
        }
742
858
        state->uri->scheme.first = NULL; /* Not a scheme, reset */
743
858
        return afterLast;
744
858
    }
745
746
39.4k
    switch (*first) {
747
9.43k
    case _UT('%'): {
748
9.43k
        const URI_CHAR * const afterPctEncoded =
749
9.43k
                URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
750
9.43k
        if (afterPctEncoded == NULL) {
751
165
            return NULL;
752
165
        }
753
9.27k
        first = afterPctEncoded;
754
9.27k
        goto tail_call;
755
9.43k
    }
756
757
194
    case _UT('@'):
758
16.3k
    case URI_SET_SUB_DELIMS(_UT):
759
1.20M
    case URI_SET_UNRESERVED(_UT):
760
29.8k
        first += 1;
761
29.8k
        goto tail_call;
762
763
148
    case _UT('/'): {
764
148
        const URI_CHAR * afterZeroMoreSlashSegs;
765
148
        const URI_CHAR * afterSegment;
766
148
        if (!URI_FUNC(PushPathSegment)(
767
148
                    state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
768
0
            URI_FUNC(StopMalloc)(state, memory);
769
0
            return NULL;
770
0
        }
771
148
        state->uri->scheme.first = NULL; /* Not a scheme, reset */
772
148
        afterSegment = URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory);
773
148
        if (afterSegment == NULL) {
774
2
            return NULL;
775
2
        }
776
146
        if (!URI_FUNC(PushPathSegment)(
777
146
                    state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */
778
0
            URI_FUNC(StopMalloc)(state, memory);
779
0
            return NULL;
780
0
        }
781
146
        afterZeroMoreSlashSegs =
782
146
                URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegment, afterLast, memory);
783
146
        if (afterZeroMoreSlashSegs == NULL) {
784
1
            return NULL;
785
1
        }
786
145
        return URI_FUNC(ParseUriTail)(state, afterZeroMoreSlashSegs, afterLast, memory);
787
146
    }
788
789
10
    default:
790
10
        if (!URI_FUNC(PushPathSegment)(
791
10
                    state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
792
0
            URI_FUNC(StopMalloc)(state, memory);
793
0
            return NULL;
794
0
        }
795
10
        state->uri->scheme.first = NULL; /* Not a scheme, reset */
796
10
        return URI_FUNC(ParseUriTail)(state, first, afterLast, memory);
797
39.4k
    }
798
39.4k
}
UriParse.c:uriParseMustBeSegmentNzNcA
Line
Count
Source
734
1.18k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
735
40.2k
tail_call:
736
40.2k
    if (first >= afterLast) {
737
858
        if (!URI_FUNC(PushPathSegment)(
738
858
                    state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
739
0
            URI_FUNC(StopMalloc)(state, memory);
740
0
            return NULL;
741
0
        }
742
858
        state->uri->scheme.first = NULL; /* Not a scheme, reset */
743
858
        return afterLast;
744
858
    }
745
746
39.4k
    switch (*first) {
747
9.43k
    case _UT('%'): {
748
9.43k
        const URI_CHAR * const afterPctEncoded =
749
9.43k
                URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
750
9.43k
        if (afterPctEncoded == NULL) {
751
165
            return NULL;
752
165
        }
753
9.27k
        first = afterPctEncoded;
754
9.27k
        goto tail_call;
755
9.43k
    }
756
757
194
    case _UT('@'):
758
16.3k
    case URI_SET_SUB_DELIMS(_UT):
759
29.8k
    case URI_SET_UNRESERVED(_UT):
760
29.8k
        first += 1;
761
29.8k
        goto tail_call;
762
763
148
    case _UT('/'): {
764
148
        const URI_CHAR * afterZeroMoreSlashSegs;
765
148
        const URI_CHAR * afterSegment;
766
148
        if (!URI_FUNC(PushPathSegment)(
767
148
                    state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
768
0
            URI_FUNC(StopMalloc)(state, memory);
769
0
            return NULL;
770
0
        }
771
148
        state->uri->scheme.first = NULL; /* Not a scheme, reset */
772
148
        afterSegment = URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory);
773
148
        if (afterSegment == NULL) {
774
2
            return NULL;
775
2
        }
776
146
        if (!URI_FUNC(PushPathSegment)(
777
146
                    state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */
778
0
            URI_FUNC(StopMalloc)(state, memory);
779
0
            return NULL;
780
0
        }
781
146
        afterZeroMoreSlashSegs =
782
146
                URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegment, afterLast, memory);
783
146
        if (afterZeroMoreSlashSegs == NULL) {
784
1
            return NULL;
785
1
        }
786
145
        return URI_FUNC(ParseUriTail)(state, afterZeroMoreSlashSegs, afterLast, memory);
787
146
    }
788
789
10
    default:
790
10
        if (!URI_FUNC(PushPathSegment)(
791
10
                    state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
792
0
            URI_FUNC(StopMalloc)(state, memory);
793
0
            return NULL;
794
0
        }
795
10
        state->uri->scheme.first = NULL; /* Not a scheme, reset */
796
10
        return URI_FUNC(ParseUriTail)(state, first, afterLast, memory);
797
39.4k
    }
798
39.4k
}
Unexecuted instantiation: UriParse.c:uriParseMustBeSegmentNzNcW
799
800
/*
801
 * [ownHost]-><[>[ipLit2][authorityTwo]
802
 * [ownHost]->[ownHost2] // can take <NULL>
803
 */
804
static URI_INLINE const URI_CHAR * URI_FUNC(ParseOwnHost)(URI_TYPE(ParserState) * state,
805
700
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
806
700
    if (first >= afterLast) {
807
3
        state->uri->hostText.afterLast = afterLast; /* HOST END */
808
3
        return afterLast;
809
3
    }
810
811
697
    switch (*first) {
812
34
    case _UT('['): {
813
34
        const URI_CHAR * const afterIpLit2 =
814
34
                URI_FUNC(ParseIpLit2)(state, first + 1, afterLast, memory);
815
34
        if (afterIpLit2 == NULL) {
816
1
            return NULL;
817
1
        }
818
33
        state->uri->hostText.first = first + 1; /* HOST BEGIN */
819
33
        return URI_FUNC(ParseAuthorityTwo)(state, afterIpLit2, afterLast);
820
34
    }
821
822
663
    default:
823
663
        return URI_FUNC(ParseOwnHost2)(state, first, afterLast, memory);
824
697
    }
825
697
}
UriParse.c:uriParseOwnHostA
Line
Count
Source
805
700
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
806
700
    if (first >= afterLast) {
807
3
        state->uri->hostText.afterLast = afterLast; /* HOST END */
808
3
        return afterLast;
809
3
    }
810
811
697
    switch (*first) {
812
34
    case _UT('['): {
813
34
        const URI_CHAR * const afterIpLit2 =
814
34
                URI_FUNC(ParseIpLit2)(state, first + 1, afterLast, memory);
815
34
        if (afterIpLit2 == NULL) {
816
1
            return NULL;
817
1
        }
818
33
        state->uri->hostText.first = first + 1; /* HOST BEGIN */
819
33
        return URI_FUNC(ParseAuthorityTwo)(state, afterIpLit2, afterLast);
820
34
    }
821
822
663
    default:
823
663
        return URI_FUNC(ParseOwnHost2)(state, first, afterLast, memory);
824
697
    }
825
697
}
Unexecuted instantiation: UriParse.c:uriParseOwnHostW
826
827
static URI_INLINE UriBool URI_FUNC(OnExitOwnHost2)(URI_TYPE(ParserState) * state,
828
655
        const URI_CHAR * first, UriMemoryManager * memory) {
829
655
    state->uri->hostText.afterLast = first; /* HOST END */
830
831
    /* Valid IPv4 or just a regname? */
832
655
    state->uri->hostData.ip4 = memory->malloc(
833
655
            memory, 1 * sizeof(UriIp4)); /* Freed when stopping on parse error */
834
655
    if (state->uri->hostData.ip4 == NULL) {
835
0
        return URI_FALSE; /* Raises malloc error */
836
0
    }
837
655
    if (URI_FUNC(ParseIpFourAddress)(state->uri->hostData.ip4->data,
838
655
                state->uri->hostText.first, state->uri->hostText.afterLast)) {
839
        /* Not IPv4 */
840
653
        memory->free(memory, state->uri->hostData.ip4);
841
653
        state->uri->hostData.ip4 = NULL;
842
653
    }
843
655
    return URI_TRUE; /* Success */
844
655
}
UriParse.c:uriOnExitOwnHost2A
Line
Count
Source
828
655
        const URI_CHAR * first, UriMemoryManager * memory) {
829
655
    state->uri->hostText.afterLast = first; /* HOST END */
830
831
    /* Valid IPv4 or just a regname? */
832
655
    state->uri->hostData.ip4 = memory->malloc(
833
655
            memory, 1 * sizeof(UriIp4)); /* Freed when stopping on parse error */
834
655
    if (state->uri->hostData.ip4 == NULL) {
835
0
        return URI_FALSE; /* Raises malloc error */
836
0
    }
837
655
    if (URI_FUNC(ParseIpFourAddress)(state->uri->hostData.ip4->data,
838
655
                state->uri->hostText.first, state->uri->hostText.afterLast)) {
839
        /* Not IPv4 */
840
653
        memory->free(memory, state->uri->hostData.ip4);
841
653
        state->uri->hostData.ip4 = NULL;
842
653
    }
843
655
    return URI_TRUE; /* Success */
844
655
}
Unexecuted instantiation: UriParse.c:uriOnExitOwnHost2W
845
846
/*
847
 * [ownHost2]->[authorityTwo] // can take <NULL>
848
 * [ownHost2]->[pctSubUnres][ownHost2]
849
 */
850
static const URI_CHAR * URI_FUNC(ParseOwnHost2)(URI_TYPE(ParserState) * state,
851
663
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
852
16.1k
tail_call:
853
16.1k
    if (first >= afterLast) {
854
620
        if (!URI_FUNC(OnExitOwnHost2)(state, first, memory)) {
855
0
            URI_FUNC(StopMalloc)(state, memory);
856
0
            return NULL;
857
0
        }
858
620
        return afterLast;
859
620
    }
860
861
15.5k
    switch (*first) {
862
211
    case _UT('%'):
863
16.7k
    case URI_SET_SUB_DELIMS(_UT):
864
598k
    case URI_SET_UNRESERVED(_UT): {
865
598k
        const URI_CHAR * const afterPctSubUnres =
866
598k
                URI_FUNC(ParsePctSubUnres)(state, first, afterLast, memory);
867
598k
        if (afterPctSubUnres == NULL) {
868
8
            return NULL;
869
8
        }
870
15.4k
        first = afterPctSubUnres;
871
15.4k
        goto tail_call;
872
598k
    }
873
874
35
    default:
875
35
        if (!URI_FUNC(OnExitOwnHost2)(state, first, memory)) {
876
0
            URI_FUNC(StopMalloc)(state, memory);
877
0
            return NULL;
878
0
        }
879
35
        return URI_FUNC(ParseAuthorityTwo)(state, first, afterLast);
880
15.5k
    }
881
15.5k
}
UriParse.c:uriParseOwnHost2A
Line
Count
Source
851
663
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
852
16.1k
tail_call:
853
16.1k
    if (first >= afterLast) {
854
620
        if (!URI_FUNC(OnExitOwnHost2)(state, first, memory)) {
855
0
            URI_FUNC(StopMalloc)(state, memory);
856
0
            return NULL;
857
0
        }
858
620
        return afterLast;
859
620
    }
860
861
15.5k
    switch (*first) {
862
211
    case _UT('%'):
863
16.7k
    case URI_SET_SUB_DELIMS(_UT):
864
598k
    case URI_SET_UNRESERVED(_UT): {
865
598k
        const URI_CHAR * const afterPctSubUnres =
866
598k
                URI_FUNC(ParsePctSubUnres)(state, first, afterLast, memory);
867
598k
        if (afterPctSubUnres == NULL) {
868
8
            return NULL;
869
8
        }
870
15.4k
        first = afterPctSubUnres;
871
15.4k
        goto tail_call;
872
598k
    }
873
874
35
    default:
875
35
        if (!URI_FUNC(OnExitOwnHost2)(state, first, memory)) {
876
0
            URI_FUNC(StopMalloc)(state, memory);
877
0
            return NULL;
878
0
        }
879
35
        return URI_FUNC(ParseAuthorityTwo)(state, first, afterLast);
880
15.5k
    }
881
15.5k
}
Unexecuted instantiation: UriParse.c:uriParseOwnHost2W
882
883
static URI_INLINE UriBool URI_FUNC(OnExitOwnHostUserInfo)(URI_TYPE(ParserState) * state,
884
793
        const URI_CHAR * first, UriMemoryManager * memory) {
885
793
    state->uri->hostText.first =
886
793
            state->uri->userInfo.first; /* Host instead of userInfo, update */
887
793
    state->uri->userInfo.first = NULL; /* Not a userInfo, reset */
888
793
    state->uri->hostText.afterLast = first; /* HOST END */
889
890
    /* Valid IPv4 or just a regname? */
891
793
    state->uri->hostData.ip4 = memory->malloc(
892
793
            memory, 1 * sizeof(UriIp4)); /* Freed when stopping on parse error */
893
793
    if (state->uri->hostData.ip4 == NULL) {
894
0
        return URI_FALSE; /* Raises malloc error */
895
0
    }
896
793
    if (URI_FUNC(ParseIpFourAddress)(state->uri->hostData.ip4->data,
897
793
                state->uri->hostText.first, state->uri->hostText.afterLast)) {
898
        /* Not IPv4 */
899
771
        memory->free(memory, state->uri->hostData.ip4);
900
771
        state->uri->hostData.ip4 = NULL;
901
771
    }
902
793
    return URI_TRUE; /* Success */
903
793
}
UriParse.c:uriOnExitOwnHostUserInfoA
Line
Count
Source
884
793
        const URI_CHAR * first, UriMemoryManager * memory) {
885
793
    state->uri->hostText.first =
886
793
            state->uri->userInfo.first; /* Host instead of userInfo, update */
887
793
    state->uri->userInfo.first = NULL; /* Not a userInfo, reset */
888
793
    state->uri->hostText.afterLast = first; /* HOST END */
889
890
    /* Valid IPv4 or just a regname? */
891
793
    state->uri->hostData.ip4 = memory->malloc(
892
793
            memory, 1 * sizeof(UriIp4)); /* Freed when stopping on parse error */
893
793
    if (state->uri->hostData.ip4 == NULL) {
894
0
        return URI_FALSE; /* Raises malloc error */
895
0
    }
896
793
    if (URI_FUNC(ParseIpFourAddress)(state->uri->hostData.ip4->data,
897
793
                state->uri->hostText.first, state->uri->hostText.afterLast)) {
898
        /* Not IPv4 */
899
771
        memory->free(memory, state->uri->hostData.ip4);
900
771
        state->uri->hostData.ip4 = NULL;
901
771
    }
902
793
    return URI_TRUE; /* Success */
903
793
}
Unexecuted instantiation: UriParse.c:uriOnExitOwnHostUserInfoW
904
905
/*
906
 * [ownHostUserInfoNz]->[pctSubUnres][ownHostUserInfo]
907
 * [ownHostUserInfoNz]-><:>[ownPortUserInfo]
908
 * [ownHostUserInfoNz]-><@>[ownHost]
909
 *
910
 * [ownHostUserInfo]->[ownHostUserInfoNz]
911
 * [ownHostUserInfo]-><NULL>
912
 */
913
static const URI_CHAR * URI_FUNC(ParseOwnHostUserInfoNz)(URI_TYPE(ParserState) * state,
914
2.30k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
915
2.30k
    const URI_CHAR * const originalFirst = first;
916
917
30.7k
    while (first < afterLast) {
918
29.9k
        switch (*first) {
919
294
        case _UT('%'):
920
23.0k
        case URI_SET_SUB_DELIMS(_UT):
921
999k
        case URI_SET_UNRESERVED(_UT): {
922
999k
            const URI_CHAR * const afterPctSubUnres =
923
999k
                    URI_FUNC(ParsePctSubUnres)(state, first, afterLast, memory);
924
999k
            if (afterPctSubUnres == NULL) {
925
9
                return NULL;
926
9
            }
927
28.4k
            first = afterPctSubUnres;
928
28.4k
            break;
929
999k
        }
930
931
1.50k
        default:
932
1.50k
            goto done_looping;
933
1.50k
            break;
934
29.9k
        }
935
29.9k
    }
936
937
2.29k
done_looping:
938
2.29k
    if (first < afterLast) {
939
1.50k
        switch (*first) {
940
802
        case _UT(':'):
941
802
            state->uri->hostText.afterLast = first; /* HOST END */
942
802
            state->uri->portText.first = first + 1; /* PORT BEGIN */
943
802
            return URI_FUNC(ParseOwnPortUserInfo)(state, first + 1, afterLast, memory);
944
945
698
        case _UT('@'):
946
698
            state->uri->userInfo.afterLast = first; /* USERINFO END */
947
698
            state->uri->hostText.first = first + 1; /* HOST BEGIN */
948
698
            return URI_FUNC(ParseOwnHost)(state, first + 1, afterLast, memory);
949
950
3
        default:
951
3
            break;
952
1.50k
        }
953
1.50k
    }
954
955
793
    if (first == originalFirst) {
956
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
957
0
        return NULL;
958
0
    }
959
960
793
    if (!URI_FUNC(OnExitOwnHostUserInfo)(state, first, memory)) {
961
0
        URI_FUNC(StopMalloc)(state, memory);
962
0
        return NULL;
963
0
    }
964
965
793
    return first;
966
793
}
UriParse.c:uriParseOwnHostUserInfoNzA
Line
Count
Source
914
2.30k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
915
2.30k
    const URI_CHAR * const originalFirst = first;
916
917
30.7k
    while (first < afterLast) {
918
29.9k
        switch (*first) {
919
294
        case _UT('%'):
920
23.0k
        case URI_SET_SUB_DELIMS(_UT):
921
999k
        case URI_SET_UNRESERVED(_UT): {
922
999k
            const URI_CHAR * const afterPctSubUnres =
923
999k
                    URI_FUNC(ParsePctSubUnres)(state, first, afterLast, memory);
924
999k
            if (afterPctSubUnres == NULL) {
925
9
                return NULL;
926
9
            }
927
28.4k
            first = afterPctSubUnres;
928
28.4k
            break;
929
999k
        }
930
931
1.50k
        default:
932
1.50k
            goto done_looping;
933
1.50k
            break;
934
29.9k
        }
935
29.9k
    }
936
937
2.29k
done_looping:
938
2.29k
    if (first < afterLast) {
939
1.50k
        switch (*first) {
940
802
        case _UT(':'):
941
802
            state->uri->hostText.afterLast = first; /* HOST END */
942
802
            state->uri->portText.first = first + 1; /* PORT BEGIN */
943
802
            return URI_FUNC(ParseOwnPortUserInfo)(state, first + 1, afterLast, memory);
944
945
698
        case _UT('@'):
946
698
            state->uri->userInfo.afterLast = first; /* USERINFO END */
947
698
            state->uri->hostText.first = first + 1; /* HOST BEGIN */
948
698
            return URI_FUNC(ParseOwnHost)(state, first + 1, afterLast, memory);
949
950
3
        default:
951
3
            break;
952
1.50k
        }
953
1.50k
    }
954
955
793
    if (first == originalFirst) {
956
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
957
0
        return NULL;
958
0
    }
959
960
793
    if (!URI_FUNC(OnExitOwnHostUserInfo)(state, first, memory)) {
961
0
        URI_FUNC(StopMalloc)(state, memory);
962
0
        return NULL;
963
0
    }
964
965
793
    return first;
966
793
}
Unexecuted instantiation: UriParse.c:uriParseOwnHostUserInfoNzW
967
968
static URI_INLINE UriBool URI_FUNC(OnExitOwnPortUserInfo)(URI_TYPE(ParserState) * state,
969
90
        const URI_CHAR * first, UriMemoryManager * memory) {
970
90
    state->uri->hostText.first =
971
90
            state->uri->userInfo.first; /* Host instead of userInfo, update */
972
90
    state->uri->userInfo.first = NULL; /* Not a userInfo, reset */
973
90
    state->uri->portText.afterLast = first; /* PORT END */
974
975
    /* Valid IPv4 or just a regname? */
976
90
    state->uri->hostData.ip4 = memory->malloc(
977
90
            memory, 1 * sizeof(UriIp4)); /* Freed when stopping on parse error */
978
90
    if (state->uri->hostData.ip4 == NULL) {
979
0
        return URI_FALSE; /* Raises malloc error */
980
0
    }
981
90
    if (URI_FUNC(ParseIpFourAddress)(state->uri->hostData.ip4->data,
982
90
                state->uri->hostText.first, state->uri->hostText.afterLast)) {
983
        /* Not IPv4 */
984
88
        memory->free(memory, state->uri->hostData.ip4);
985
88
        state->uri->hostData.ip4 = NULL;
986
88
    }
987
90
    return URI_TRUE; /* Success */
988
90
}
UriParse.c:uriOnExitOwnPortUserInfoA
Line
Count
Source
969
90
        const URI_CHAR * first, UriMemoryManager * memory) {
970
90
    state->uri->hostText.first =
971
90
            state->uri->userInfo.first; /* Host instead of userInfo, update */
972
90
    state->uri->userInfo.first = NULL; /* Not a userInfo, reset */
973
90
    state->uri->portText.afterLast = first; /* PORT END */
974
975
    /* Valid IPv4 or just a regname? */
976
90
    state->uri->hostData.ip4 = memory->malloc(
977
90
            memory, 1 * sizeof(UriIp4)); /* Freed when stopping on parse error */
978
90
    if (state->uri->hostData.ip4 == NULL) {
979
0
        return URI_FALSE; /* Raises malloc error */
980
0
    }
981
90
    if (URI_FUNC(ParseIpFourAddress)(state->uri->hostData.ip4->data,
982
90
                state->uri->hostText.first, state->uri->hostText.afterLast)) {
983
        /* Not IPv4 */
984
88
        memory->free(memory, state->uri->hostData.ip4);
985
88
        state->uri->hostData.ip4 = NULL;
986
88
    }
987
90
    return URI_TRUE; /* Success */
988
90
}
Unexecuted instantiation: UriParse.c:uriOnExitOwnPortUserInfoW
989
990
/*
991
 * [ownPortUserInfo]->[ALPHA][ownUserInfo]
992
 * [ownPortUserInfo]->[DIGIT][ownPortUserInfo]
993
 * [ownPortUserInfo]-><.>[ownUserInfo]
994
 * [ownPortUserInfo]-><_>[ownUserInfo]
995
 * [ownPortUserInfo]-><~>[ownUserInfo]
996
 * [ownPortUserInfo]-><->[ownUserInfo]
997
 * [ownPortUserInfo]->[subDelims][ownUserInfo]
998
 * [ownPortUserInfo]->[pctEncoded][ownUserInfo]
999
 * [ownPortUserInfo]-><:>[ownUserInfo]
1000
 * [ownPortUserInfo]-><@>[ownHost]
1001
 * [ownPortUserInfo]-><NULL>
1002
 */
1003
static const URI_CHAR * URI_FUNC(ParseOwnPortUserInfo)(URI_TYPE(ParserState) * state,
1004
802
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1005
2.94k
tail_call:
1006
2.94k
    if (first >= afterLast) {
1007
88
        if (!URI_FUNC(OnExitOwnPortUserInfo)(state, first, memory)) {
1008
0
            URI_FUNC(StopMalloc)(state, memory);
1009
0
            return NULL;
1010
0
        }
1011
88
        return afterLast;
1012
88
    }
1013
1014
2.85k
    switch (*first) {
1015
805
    case URI_SET_SUB_DELIMS(_UT):
1016
    /* begin unreserved (except alpha and digit) */
1017
805
    case _UT('-'):
1018
158
    case _UT('.'):
1019
165
    case _UT('_'):
1020
176
    case _UT('~'):
1021
    /* end unreserved (except alpha and digit) */
1022
205
    case _UT(':'):
1023
23.6k
    case URI_SET_ALPHA(_UT):
1024
709
        state->uri->hostText.afterLast = NULL; /* Not a host, reset */
1025
709
        state->uri->portText.first = NULL; /* Not a port, reset */
1026
709
        return URI_FUNC(ParseOwnUserInfo)(state, first + 1, afterLast, memory);
1027
1028
10.2k
    case URI_SET_DIGIT(_UT):
1029
2.13k
        first += 1;
1030
2.13k
        goto tail_call;
1031
1032
2
    case _UT('%'):
1033
2
        state->uri->portText.first = NULL; /* Not a port, reset */
1034
2
        const URI_CHAR * const afterPct =
1035
2
                URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1036
2
        if (afterPct == NULL) {
1037
1
            return NULL;
1038
1
        }
1039
1
        return URI_FUNC(ParseOwnUserInfo)(state, afterPct, afterLast, memory);
1040
1041
1
    case _UT('@'):
1042
1
        state->uri->hostText.afterLast = NULL; /* Not a host, reset */
1043
1
        state->uri->portText.first = NULL; /* Not a port, reset */
1044
1
        state->uri->userInfo.afterLast = first; /* USERINFO END */
1045
1
        state->uri->hostText.first = first + 1; /* HOST BEGIN */
1046
1
        return URI_FUNC(ParseOwnHost)(state, first + 1, afterLast, memory);
1047
1048
2
    default:
1049
2
        if (!URI_FUNC(OnExitOwnPortUserInfo)(state, first, memory)) {
1050
0
            URI_FUNC(StopMalloc)(state, memory);
1051
0
            return NULL;
1052
0
        }
1053
2
        return first;
1054
2.85k
    }
1055
2.85k
}
UriParse.c:uriParseOwnPortUserInfoA
Line
Count
Source
1004
802
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1005
2.94k
tail_call:
1006
2.94k
    if (first >= afterLast) {
1007
88
        if (!URI_FUNC(OnExitOwnPortUserInfo)(state, first, memory)) {
1008
0
            URI_FUNC(StopMalloc)(state, memory);
1009
0
            return NULL;
1010
0
        }
1011
88
        return afterLast;
1012
88
    }
1013
1014
2.85k
    switch (*first) {
1015
805
    case URI_SET_SUB_DELIMS(_UT):
1016
    /* begin unreserved (except alpha and digit) */
1017
805
    case _UT('-'):
1018
158
    case _UT('.'):
1019
165
    case _UT('_'):
1020
176
    case _UT('~'):
1021
    /* end unreserved (except alpha and digit) */
1022
205
    case _UT(':'):
1023
709
    case URI_SET_ALPHA(_UT):
1024
709
        state->uri->hostText.afterLast = NULL; /* Not a host, reset */
1025
709
        state->uri->portText.first = NULL; /* Not a port, reset */
1026
709
        return URI_FUNC(ParseOwnUserInfo)(state, first + 1, afterLast, memory);
1027
1028
2.13k
    case URI_SET_DIGIT(_UT):
1029
2.13k
        first += 1;
1030
2.13k
        goto tail_call;
1031
1032
2
    case _UT('%'):
1033
2
        state->uri->portText.first = NULL; /* Not a port, reset */
1034
2
        const URI_CHAR * const afterPct =
1035
2
                URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1036
2
        if (afterPct == NULL) {
1037
1
            return NULL;
1038
1
        }
1039
1
        return URI_FUNC(ParseOwnUserInfo)(state, afterPct, afterLast, memory);
1040
1041
1
    case _UT('@'):
1042
1
        state->uri->hostText.afterLast = NULL; /* Not a host, reset */
1043
1
        state->uri->portText.first = NULL; /* Not a port, reset */
1044
1
        state->uri->userInfo.afterLast = first; /* USERINFO END */
1045
1
        state->uri->hostText.first = first + 1; /* HOST BEGIN */
1046
1
        return URI_FUNC(ParseOwnHost)(state, first + 1, afterLast, memory);
1047
1048
2
    default:
1049
2
        if (!URI_FUNC(OnExitOwnPortUserInfo)(state, first, memory)) {
1050
0
            URI_FUNC(StopMalloc)(state, memory);
1051
0
            return NULL;
1052
0
        }
1053
2
        return first;
1054
2.85k
    }
1055
2.85k
}
Unexecuted instantiation: UriParse.c:uriParseOwnPortUserInfoW
1056
1057
/*
1058
 * [ownUserInfo]->[pctSubUnres][ownUserInfo]
1059
 * [ownUserInfo]-><:>[ownUserInfo]
1060
 * [ownUserInfo]-><@>[ownHost]
1061
 */
1062
static const URI_CHAR * URI_FUNC(ParseOwnUserInfo)(URI_TYPE(ParserState) * state,
1063
710
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1064
16.2k
tail_call:
1065
16.2k
    if (first >= afterLast) {
1066
699
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1067
699
        return NULL;
1068
699
    }
1069
1070
15.5k
    switch (*first) {
1071
194
    case _UT('%'):
1072
14.7k
    case URI_SET_SUB_DELIMS(_UT):
1073
588k
    case URI_SET_UNRESERVED(_UT): {
1074
588k
        const URI_CHAR * const afterPctSubUnres =
1075
588k
                URI_FUNC(ParsePctSubUnres)(state, first, afterLast, memory);
1076
588k
        if (afterPctSubUnres == NULL) {
1077
8
            return NULL;
1078
8
        }
1079
15.3k
        first = afterPctSubUnres;
1080
15.3k
        goto tail_call;
1081
588k
    }
1082
1083
195
    case _UT(':'):
1084
195
        first += 1;
1085
195
        goto tail_call;
1086
1087
1
    case _UT('@'):
1088
        /* SURE */
1089
1
        state->uri->userInfo.afterLast = first; /* USERINFO END */
1090
1
        state->uri->hostText.first = first + 1; /* HOST BEGIN */
1091
1
        return URI_FUNC(ParseOwnHost)(state, first + 1, afterLast, memory);
1092
1093
2
    default:
1094
2
        URI_FUNC(StopSyntax)(state, first, memory);
1095
2
        return NULL;
1096
15.5k
    }
1097
15.5k
}
UriParse.c:uriParseOwnUserInfoA
Line
Count
Source
1063
710
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1064
16.2k
tail_call:
1065
16.2k
    if (first >= afterLast) {
1066
699
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1067
699
        return NULL;
1068
699
    }
1069
1070
15.5k
    switch (*first) {
1071
194
    case _UT('%'):
1072
14.7k
    case URI_SET_SUB_DELIMS(_UT):
1073
588k
    case URI_SET_UNRESERVED(_UT): {
1074
588k
        const URI_CHAR * const afterPctSubUnres =
1075
588k
                URI_FUNC(ParsePctSubUnres)(state, first, afterLast, memory);
1076
588k
        if (afterPctSubUnres == NULL) {
1077
8
            return NULL;
1078
8
        }
1079
15.3k
        first = afterPctSubUnres;
1080
15.3k
        goto tail_call;
1081
588k
    }
1082
1083
195
    case _UT(':'):
1084
195
        first += 1;
1085
195
        goto tail_call;
1086
1087
1
    case _UT('@'):
1088
        /* SURE */
1089
1
        state->uri->userInfo.afterLast = first; /* USERINFO END */
1090
1
        state->uri->hostText.first = first + 1; /* HOST BEGIN */
1091
1
        return URI_FUNC(ParseOwnHost)(state, first + 1, afterLast, memory);
1092
1093
2
    default:
1094
2
        URI_FUNC(StopSyntax)(state, first, memory);
1095
        return NULL;
1096
15.5k
    }
1097
15.5k
}
Unexecuted instantiation: UriParse.c:uriParseOwnUserInfoW
1098
1099
636
static URI_INLINE void URI_FUNC(OnExitPartHelperTwo)(URI_TYPE(ParserState) * state) {
1100
636
    state->uri->absolutePath = URI_TRUE;
1101
636
}
UriParse.c:uriOnExitPartHelperTwoA
Line
Count
Source
1099
636
static URI_INLINE void URI_FUNC(OnExitPartHelperTwo)(URI_TYPE(ParserState) * state) {
1100
636
    state->uri->absolutePath = URI_TRUE;
1101
636
}
Unexecuted instantiation: UriParse.c:uriOnExitPartHelperTwoW
1102
1103
/*
1104
 * [partHelperTwo]->[pathAbsNoLeadSlash] // can take <NULL>
1105
 * [partHelperTwo]-></>[authority][pathAbsEmpty]
1106
 */
1107
static URI_INLINE const URI_CHAR * URI_FUNC(ParsePartHelperTwo)(
1108
        URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast,
1109
4.31k
        UriMemoryManager * memory) {
1110
4.31k
    if (first >= afterLast) {
1111
2
        URI_FUNC(OnExitPartHelperTwo)(state);
1112
2
        return afterLast;
1113
2
    }
1114
1115
4.31k
    switch (*first) {
1116
3.67k
    case _UT('/'): {
1117
3.67k
        const URI_CHAR * const afterAuthority =
1118
3.67k
                URI_FUNC(ParseAuthority)(state, first + 1, afterLast, memory);
1119
3.67k
        const URI_CHAR * afterPathAbsEmpty;
1120
3.67k
        if (afterAuthority == NULL) {
1121
2.02k
            return NULL;
1122
2.02k
        }
1123
1.65k
        afterPathAbsEmpty =
1124
1.65k
                URI_FUNC(ParsePathAbsEmpty)(state, afterAuthority, afterLast, memory);
1125
1126
1.65k
        URI_FUNC(FixEmptyTrailSegment)(state->uri, memory);
1127
1128
1.65k
        return afterPathAbsEmpty;
1129
3.67k
    }
1130
1131
634
    default:
1132
634
        URI_FUNC(OnExitPartHelperTwo)(state);
1133
634
        return URI_FUNC(ParsePathAbsNoLeadSlash)(state, first, afterLast, memory);
1134
4.31k
    }
1135
4.31k
}
UriParse.c:uriParsePartHelperTwoA
Line
Count
Source
1109
4.31k
        UriMemoryManager * memory) {
1110
4.31k
    if (first >= afterLast) {
1111
2
        URI_FUNC(OnExitPartHelperTwo)(state);
1112
2
        return afterLast;
1113
2
    }
1114
1115
4.31k
    switch (*first) {
1116
3.67k
    case _UT('/'): {
1117
3.67k
        const URI_CHAR * const afterAuthority =
1118
3.67k
                URI_FUNC(ParseAuthority)(state, first + 1, afterLast, memory);
1119
3.67k
        const URI_CHAR * afterPathAbsEmpty;
1120
3.67k
        if (afterAuthority == NULL) {
1121
2.02k
            return NULL;
1122
2.02k
        }
1123
1.65k
        afterPathAbsEmpty =
1124
1.65k
                URI_FUNC(ParsePathAbsEmpty)(state, afterAuthority, afterLast, memory);
1125
1126
1.65k
        URI_FUNC(FixEmptyTrailSegment)(state->uri, memory);
1127
1128
1.65k
        return afterPathAbsEmpty;
1129
3.67k
    }
1130
1131
634
    default:
1132
634
        URI_FUNC(OnExitPartHelperTwo)(state);
1133
634
        return URI_FUNC(ParsePathAbsNoLeadSlash)(state, first, afterLast, memory);
1134
4.31k
    }
1135
4.31k
}
Unexecuted instantiation: UriParse.c:uriParsePartHelperTwoW
1136
1137
/*
1138
 * [pathAbsEmpty]-></>[segment][pathAbsEmpty]
1139
 * [pathAbsEmpty]-><NULL>
1140
 */
1141
static const URI_CHAR * URI_FUNC(ParsePathAbsEmpty)(URI_TYPE(ParserState) * state,
1142
1.65k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1143
2.26k
tail_call:
1144
2.26k
    if (first >= afterLast) {
1145
1.57k
        return afterLast;
1146
1.57k
    }
1147
1148
689
    switch (*first) {
1149
612
    case _UT('/'): {
1150
612
        const URI_CHAR * const afterSegment =
1151
612
                URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory);
1152
612
        if (afterSegment == NULL) {
1153
3
            return NULL;
1154
3
        }
1155
609
        if (!URI_FUNC(PushPathSegment)(
1156
609
                    state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */
1157
0
            URI_FUNC(StopMalloc)(state, memory);
1158
0
            return NULL;
1159
0
        }
1160
609
        first = afterSegment;
1161
609
        goto tail_call;
1162
609
    }
1163
1164
77
    default:
1165
77
        return first;
1166
689
    }
1167
689
}
UriParse.c:uriParsePathAbsEmptyA
Line
Count
Source
1142
1.65k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1143
2.26k
tail_call:
1144
2.26k
    if (first >= afterLast) {
1145
1.57k
        return afterLast;
1146
1.57k
    }
1147
1148
689
    switch (*first) {
1149
612
    case _UT('/'): {
1150
612
        const URI_CHAR * const afterSegment =
1151
612
                URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory);
1152
612
        if (afterSegment == NULL) {
1153
3
            return NULL;
1154
3
        }
1155
609
        if (!URI_FUNC(PushPathSegment)(
1156
609
                    state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */
1157
0
            URI_FUNC(StopMalloc)(state, memory);
1158
0
            return NULL;
1159
0
        }
1160
609
        first = afterSegment;
1161
609
        goto tail_call;
1162
609
    }
1163
1164
77
    default:
1165
77
        return first;
1166
689
    }
1167
689
}
Unexecuted instantiation: UriParse.c:uriParsePathAbsEmptyW
1168
1169
/*
1170
 * [pathAbsNoLeadSlash]->[segmentNz][zeroMoreSlashSegs]
1171
 * [pathAbsNoLeadSlash]-><NULL>
1172
 */
1173
static URI_INLINE const URI_CHAR * URI_FUNC(ParsePathAbsNoLeadSlash)(
1174
        URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast,
1175
634
        UriMemoryManager * memory) {
1176
634
    if (first >= afterLast) {
1177
0
        return afterLast;
1178
0
    }
1179
1180
634
    switch (*first) {
1181
23.0k
    case URI_SET_PCHAR(_UT): {
1182
23.0k
        const URI_CHAR * const afterSegmentNz =
1183
23.0k
                URI_FUNC(ParseSegmentNz)(state, first, afterLast, memory);
1184
23.0k
        if (afterSegmentNz == NULL) {
1185
7
            return NULL;
1186
7
        }
1187
623
        if (!URI_FUNC(PushPathSegment)(
1188
623
                    state, first, afterSegmentNz, memory)) { /* SEGMENT BOTH */
1189
0
            URI_FUNC(StopMalloc)(state, memory);
1190
0
            return NULL;
1191
0
        }
1192
623
        return URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegmentNz, afterLast, memory);
1193
623
    }
1194
1195
4
    default:
1196
4
        return first;
1197
634
    }
1198
634
}
UriParse.c:uriParsePathAbsNoLeadSlashA
Line
Count
Source
1175
634
        UriMemoryManager * memory) {
1176
634
    if (first >= afterLast) {
1177
0
        return afterLast;
1178
0
    }
1179
1180
634
    switch (*first) {
1181
23.0k
    case URI_SET_PCHAR(_UT): {
1182
23.0k
        const URI_CHAR * const afterSegmentNz =
1183
23.0k
                URI_FUNC(ParseSegmentNz)(state, first, afterLast, memory);
1184
23.0k
        if (afterSegmentNz == NULL) {
1185
7
            return NULL;
1186
7
        }
1187
623
        if (!URI_FUNC(PushPathSegment)(
1188
623
                    state, first, afterSegmentNz, memory)) { /* SEGMENT BOTH */
1189
0
            URI_FUNC(StopMalloc)(state, memory);
1190
0
            return NULL;
1191
0
        }
1192
623
        return URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegmentNz, afterLast, memory);
1193
623
    }
1194
1195
4
    default:
1196
4
        return first;
1197
634
    }
1198
634
}
Unexecuted instantiation: UriParse.c:uriParsePathAbsNoLeadSlashW
1199
1200
/*
1201
 * [pathRootless]->[segmentNz][zeroMoreSlashSegs]
1202
 */
1203
static URI_INLINE const URI_CHAR * URI_FUNC(ParsePathRootless)(
1204
        URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast,
1205
113
        UriMemoryManager * memory) {
1206
113
    const URI_CHAR * const afterSegmentNz =
1207
113
            URI_FUNC(ParseSegmentNz)(state, first, afterLast, memory);
1208
113
    if (afterSegmentNz == NULL) {
1209
2
        return NULL;
1210
111
    } else {
1211
111
        if (!URI_FUNC(PushPathSegment)(
1212
111
                    state, first, afterSegmentNz, memory)) { /* SEGMENT BOTH */
1213
0
            URI_FUNC(StopMalloc)(state, memory);
1214
0
            return NULL;
1215
0
        }
1216
111
    }
1217
111
    return URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegmentNz, afterLast, memory);
1218
113
}
UriParse.c:uriParsePathRootlessA
Line
Count
Source
1205
113
        UriMemoryManager * memory) {
1206
113
    const URI_CHAR * const afterSegmentNz =
1207
113
            URI_FUNC(ParseSegmentNz)(state, first, afterLast, memory);
1208
113
    if (afterSegmentNz == NULL) {
1209
2
        return NULL;
1210
111
    } else {
1211
111
        if (!URI_FUNC(PushPathSegment)(
1212
111
                    state, first, afterSegmentNz, memory)) { /* SEGMENT BOTH */
1213
0
            URI_FUNC(StopMalloc)(state, memory);
1214
0
            return NULL;
1215
0
        }
1216
111
    }
1217
111
    return URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegmentNz, afterLast, memory);
1218
113
}
Unexecuted instantiation: UriParse.c:uriParsePathRootlessW
1219
1220
/*
1221
 * [pchar]->[pctEncoded]
1222
 * [pchar]->[subDelims]
1223
 * [pchar]->[unreserved]
1224
 * [pchar]-><:>
1225
 * [pchar]-><@>
1226
 */
1227
static const URI_CHAR * URI_FUNC(ParsePchar)(URI_TYPE(ParserState) * state,
1228
627k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1229
627k
    if (first >= afterLast) {
1230
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1231
0
        return NULL;
1232
0
    }
1233
1234
627k
    switch (*first) {
1235
6.97k
    case _UT('%'):
1236
6.97k
        return URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1237
1238
22.4M
    case URI_SET_PCHAR_WITHOUT_PERCENT(_UT):
1239
620k
        return first + 1;
1240
1241
0
    default:
1242
0
        URI_FUNC(StopSyntax)(state, first, memory);
1243
0
        return NULL;
1244
627k
    }
1245
627k
}
UriParse.c:uriParsePcharA
Line
Count
Source
1228
627k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1229
627k
    if (first >= afterLast) {
1230
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1231
0
        return NULL;
1232
0
    }
1233
1234
627k
    switch (*first) {
1235
6.97k
    case _UT('%'):
1236
6.97k
        return URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1237
1238
620k
    case URI_SET_PCHAR_WITHOUT_PERCENT(_UT):
1239
620k
        return first + 1;
1240
1241
0
    default:
1242
0
        URI_FUNC(StopSyntax)(state, first, memory);
1243
        return NULL;
1244
627k
    }
1245
627k
}
Unexecuted instantiation: UriParse.c:uriParsePcharW
1246
1247
/*
1248
 * [pctEncoded]-><%>[HEXDIG][HEXDIG]
1249
 */
1250
static const URI_CHAR * URI_FUNC(ParsePctEncoded)(URI_TYPE(ParserState) * state,
1251
17.4k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1252
17.4k
    if (first >= afterLast) {
1253
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1254
0
        return NULL;
1255
0
    }
1256
1257
    /*
1258
    First character has already been
1259
    checked before entering this rule.
1260
1261
    switch (*first) {
1262
    case _UT('%'):
1263
    */
1264
17.4k
    if (afterLast - first < 2) {
1265
64
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1266
64
        return NULL;
1267
64
    }
1268
1269
17.4k
    switch (first[1]) {
1270
234k
    case URI_SET_HEXDIG(_UT):
1271
234k
        if (afterLast - first < 3) {
1272
173
            URI_FUNC(StopSyntax)(state, afterLast, memory);
1273
173
            return NULL;
1274
173
        }
1275
1276
17.2k
        switch (first[2]) {
1277
172k
        case URI_SET_HEXDIG(_UT):
1278
17.2k
            return first + 3;
1279
1280
8
        default:
1281
8
            URI_FUNC(StopSyntax)(state, first + 2, memory);
1282
8
            return NULL;
1283
17.2k
        }
1284
1285
6
    default:
1286
6
        URI_FUNC(StopSyntax)(state, first + 1, memory);
1287
6
        return NULL;
1288
17.4k
    }
1289
1290
    /*
1291
    default:
1292
            URI_FUNC(StopSyntax)(state, first, memory);
1293
            return NULL;
1294
    }
1295
    */
1296
17.4k
}
UriParse.c:uriParsePctEncodedA
Line
Count
Source
1251
17.4k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1252
17.4k
    if (first >= afterLast) {
1253
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1254
0
        return NULL;
1255
0
    }
1256
1257
    /*
1258
    First character has already been
1259
    checked before entering this rule.
1260
1261
    switch (*first) {
1262
    case _UT('%'):
1263
    */
1264
17.4k
    if (afterLast - first < 2) {
1265
64
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1266
64
        return NULL;
1267
64
    }
1268
1269
17.4k
    switch (first[1]) {
1270
234k
    case URI_SET_HEXDIG(_UT):
1271
234k
        if (afterLast - first < 3) {
1272
173
            URI_FUNC(StopSyntax)(state, afterLast, memory);
1273
173
            return NULL;
1274
173
        }
1275
1276
17.2k
        switch (first[2]) {
1277
17.2k
        case URI_SET_HEXDIG(_UT):
1278
17.2k
            return first + 3;
1279
1280
8
        default:
1281
8
            URI_FUNC(StopSyntax)(state, first + 2, memory);
1282
8
            return NULL;
1283
17.2k
        }
1284
1285
6
    default:
1286
6
        URI_FUNC(StopSyntax)(state, first + 1, memory);
1287
6
        return NULL;
1288
17.4k
    }
1289
1290
    /*
1291
    default:
1292
            URI_FUNC(StopSyntax)(state, first, memory);
1293
            return NULL;
1294
    }
1295
    */
1296
17.4k
}
Unexecuted instantiation: UriParse.c:uriParsePctEncodedW
1297
1298
/*
1299
 * [pctSubUnres]->[pctEncoded]
1300
 * [pctSubUnres]->[subDelims]
1301
 * [pctSubUnres]->[unreserved]
1302
 */
1303
static const URI_CHAR * URI_FUNC(ParsePctSubUnres)(URI_TYPE(ParserState) * state,
1304
59.2k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1305
59.2k
    if (first >= afterLast) {
1306
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1307
0
        return NULL;
1308
0
    }
1309
1310
59.2k
    switch (*first) {
1311
699
    case _UT('%'):
1312
699
        return URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1313
1314
47.5k
    case URI_SET_SUB_DELIMS(_UT):
1315
2.04M
    case URI_SET_UNRESERVED(_UT):
1316
58.5k
        return first + 1;
1317
1318
0
    default:
1319
0
        URI_FUNC(StopSyntax)(state, first, memory);
1320
0
        return NULL;
1321
59.2k
    }
1322
59.2k
}
UriParse.c:uriParsePctSubUnresA
Line
Count
Source
1304
59.2k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1305
59.2k
    if (first >= afterLast) {
1306
0
        URI_FUNC(StopSyntax)(state, afterLast, memory);
1307
0
        return NULL;
1308
0
    }
1309
1310
59.2k
    switch (*first) {
1311
699
    case _UT('%'):
1312
699
        return URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1313
1314
47.5k
    case URI_SET_SUB_DELIMS(_UT):
1315
58.5k
    case URI_SET_UNRESERVED(_UT):
1316
58.5k
        return first + 1;
1317
1318
0
    default:
1319
0
        URI_FUNC(StopSyntax)(state, first, memory);
1320
        return NULL;
1321
59.2k
    }
1322
59.2k
}
Unexecuted instantiation: UriParse.c:uriParsePctSubUnresW
1323
1324
/*
1325
 * [port]->[DIGIT][port]
1326
 * [port]-><NULL>
1327
 */
1328
static const URI_CHAR * URI_FUNC(ParsePort)(
1329
62
        const URI_CHAR * first, const URI_CHAR * afterLast) {
1330
785
tail_call:
1331
785
    if (first >= afterLast) {
1332
24
        return afterLast;
1333
24
    }
1334
1335
761
    switch (*first) {
1336
4.55k
    case URI_SET_DIGIT(_UT):
1337
723
        first += 1;
1338
723
        goto tail_call;
1339
1340
38
    default:
1341
38
        return first;
1342
761
    }
1343
761
}
UriParse.c:uriParsePortA
Line
Count
Source
1329
62
        const URI_CHAR * first, const URI_CHAR * afterLast) {
1330
785
tail_call:
1331
785
    if (first >= afterLast) {
1332
24
        return afterLast;
1333
24
    }
1334
1335
761
    switch (*first) {
1336
723
    case URI_SET_DIGIT(_UT):
1337
723
        first += 1;
1338
723
        goto tail_call;
1339
1340
38
    default:
1341
38
        return first;
1342
761
    }
1343
761
}
Unexecuted instantiation: UriParse.c:uriParsePortW
1344
1345
/*
1346
 * [queryFrag]->[pchar][queryFrag]
1347
 * [queryFrag]-></>[queryFrag]
1348
 * [queryFrag]-><?>[queryFrag]
1349
 * [queryFrag]-><NULL>
1350
 */
1351
static const URI_CHAR * URI_FUNC(ParseQueryFrag)(URI_TYPE(ParserState) * state,
1352
695
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1353
559k
tail_call:
1354
559k
    if (first >= afterLast) {
1355
663
        return afterLast;
1356
663
    }
1357
1358
558k
    switch (*first) {
1359
21.0M
    case URI_SET_PCHAR(_UT): {
1360
21.0M
        const URI_CHAR * const afterPchar =
1361
21.0M
                URI_FUNC(ParsePchar)(state, first, afterLast, memory);
1362
21.0M
        if (afterPchar == NULL) {
1363
12
            return NULL;
1364
12
        }
1365
555k
        first = afterPchar;
1366
555k
        goto tail_call;
1367
21.0M
    }
1368
1369
2.67k
    case _UT('/'):
1370
3.03k
    case _UT('?'):
1371
3.03k
        first += 1;
1372
3.03k
        goto tail_call;
1373
1374
20
    default:
1375
20
        return first;
1376
558k
    }
1377
558k
}
UriParse.c:uriParseQueryFragA
Line
Count
Source
1352
695
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1353
559k
tail_call:
1354
559k
    if (first >= afterLast) {
1355
663
        return afterLast;
1356
663
    }
1357
1358
558k
    switch (*first) {
1359
21.0M
    case URI_SET_PCHAR(_UT): {
1360
21.0M
        const URI_CHAR * const afterPchar =
1361
21.0M
                URI_FUNC(ParsePchar)(state, first, afterLast, memory);
1362
21.0M
        if (afterPchar == NULL) {
1363
12
            return NULL;
1364
12
        }
1365
555k
        first = afterPchar;
1366
555k
        goto tail_call;
1367
21.0M
    }
1368
1369
2.67k
    case _UT('/'):
1370
3.03k
    case _UT('?'):
1371
3.03k
        first += 1;
1372
3.03k
        goto tail_call;
1373
1374
20
    default:
1375
20
        return first;
1376
558k
    }
1377
558k
}
Unexecuted instantiation: UriParse.c:uriParseQueryFragW
1378
1379
/*
1380
 * [segment]->[pchar][segment]
1381
 * [segment]-><NULL>
1382
 */
1383
static const URI_CHAR * URI_FUNC(ParseSegment)(URI_TYPE(ParserState) * state,
1384
5.48k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1385
76.6k
tail_call:
1386
76.6k
    if (first >= afterLast) {
1387
991
        return afterLast;
1388
991
    }
1389
1390
75.6k
    switch (*first) {
1391
4.01M
    case URI_SET_PCHAR(_UT): {
1392
4.01M
        const URI_CHAR * const afterPchar =
1393
4.01M
                URI_FUNC(ParsePchar)(state, first, afterLast, memory);
1394
4.01M
        if (afterPchar == NULL) {
1395
19
            return NULL;
1396
19
        }
1397
71.1k
        first = afterPchar;
1398
71.1k
        goto tail_call;
1399
4.01M
    }
1400
1401
4.47k
    default:
1402
4.47k
        return first;
1403
75.6k
    }
1404
75.6k
}
UriParse.c:uriParseSegmentA
Line
Count
Source
1384
5.48k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1385
76.6k
tail_call:
1386
76.6k
    if (first >= afterLast) {
1387
991
        return afterLast;
1388
991
    }
1389
1390
75.6k
    switch (*first) {
1391
4.01M
    case URI_SET_PCHAR(_UT): {
1392
4.01M
        const URI_CHAR * const afterPchar =
1393
4.01M
                URI_FUNC(ParsePchar)(state, first, afterLast, memory);
1394
4.01M
        if (afterPchar == NULL) {
1395
19
            return NULL;
1396
19
        }
1397
71.1k
        first = afterPchar;
1398
71.1k
        goto tail_call;
1399
4.01M
    }
1400
1401
4.47k
    default:
1402
4.47k
        return first;
1403
75.6k
    }
1404
75.6k
}
Unexecuted instantiation: UriParse.c:uriParseSegmentW
1405
1406
/*
1407
 * [segmentNz]->[pchar][segment]
1408
 */
1409
static URI_INLINE const URI_CHAR * URI_FUNC(ParseSegmentNz)(URI_TYPE(ParserState) * state,
1410
743
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1411
743
    const URI_CHAR * const afterPchar =
1412
743
            URI_FUNC(ParsePchar)(state, first, afterLast, memory);
1413
743
    if (afterPchar == NULL) {
1414
2
        return NULL;
1415
2
    }
1416
741
    return URI_FUNC(ParseSegment)(state, afterPchar, afterLast, memory);
1417
743
}
UriParse.c:uriParseSegmentNzA
Line
Count
Source
1410
743
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1411
743
    const URI_CHAR * const afterPchar =
1412
743
            URI_FUNC(ParsePchar)(state, first, afterLast, memory);
1413
743
    if (afterPchar == NULL) {
1414
2
        return NULL;
1415
2
    }
1416
741
    return URI_FUNC(ParseSegment)(state, afterPchar, afterLast, memory);
1417
743
}
Unexecuted instantiation: UriParse.c:uriParseSegmentNzW
1418
1419
static URI_INLINE UriBool URI_FUNC(OnExitSegmentNzNcOrScheme2)(
1420
        URI_TYPE(ParserState) * state, const URI_CHAR * first,
1421
584
        UriMemoryManager * memory) {
1422
584
    if (!URI_FUNC(PushPathSegment)(
1423
584
                state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
1424
0
        return URI_FALSE; /* Raises malloc error*/
1425
0
    }
1426
584
    state->uri->scheme.first = NULL; /* Not a scheme, reset */
1427
584
    return URI_TRUE; /* Success */
1428
584
}
UriParse.c:uriOnExitSegmentNzNcOrScheme2A
Line
Count
Source
1421
584
        UriMemoryManager * memory) {
1422
584
    if (!URI_FUNC(PushPathSegment)(
1423
584
                state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
1424
0
        return URI_FALSE; /* Raises malloc error*/
1425
0
    }
1426
584
    state->uri->scheme.first = NULL; /* Not a scheme, reset */
1427
584
    return URI_TRUE; /* Success */
1428
584
}
Unexecuted instantiation: UriParse.c:uriOnExitSegmentNzNcOrScheme2W
1429
1430
/*
1431
 * [segmentNzNcOrScheme2]->[ALPHA][segmentNzNcOrScheme2]
1432
 * [segmentNzNcOrScheme2]->[DIGIT][segmentNzNcOrScheme2]
1433
 * [segmentNzNcOrScheme2]->[pctEncoded][mustBeSegmentNzNc]
1434
 * [segmentNzNcOrScheme2]->[uriTail] // can take <NULL>
1435
 * [segmentNzNcOrScheme2]-><!>[mustBeSegmentNzNc]
1436
 * [segmentNzNcOrScheme2]-><$>[mustBeSegmentNzNc]
1437
 * [segmentNzNcOrScheme2]-><&>[mustBeSegmentNzNc]
1438
 * [segmentNzNcOrScheme2]-><(>[mustBeSegmentNzNc]
1439
 * [segmentNzNcOrScheme2]-><)>[mustBeSegmentNzNc]
1440
 * [segmentNzNcOrScheme2]-><*>[mustBeSegmentNzNc]
1441
 * [segmentNzNcOrScheme2]-><,>[mustBeSegmentNzNc]
1442
 * [segmentNzNcOrScheme2]-><.>[segmentNzNcOrScheme2]
1443
 * [segmentNzNcOrScheme2]-></>[segment][zeroMoreSlashSegs][uriTail]
1444
 * [segmentNzNcOrScheme2]-><:>[hierPart][uriTail]
1445
 * [segmentNzNcOrScheme2]-><;>[mustBeSegmentNzNc]
1446
 * [segmentNzNcOrScheme2]-><@>[mustBeSegmentNzNc]
1447
 * [segmentNzNcOrScheme2]-><_>[mustBeSegmentNzNc]
1448
 * [segmentNzNcOrScheme2]-><~>[mustBeSegmentNzNc]
1449
 * [segmentNzNcOrScheme2]-><+>[segmentNzNcOrScheme2]
1450
 * [segmentNzNcOrScheme2]-><=>[mustBeSegmentNzNc]
1451
 * [segmentNzNcOrScheme2]-><'>[mustBeSegmentNzNc]
1452
 * [segmentNzNcOrScheme2]-><->[segmentNzNcOrScheme2]
1453
 */
1454
static const URI_CHAR * URI_FUNC(ParseSegmentNzNcOrScheme2)(URI_TYPE(ParserState) * state,
1455
858
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1456
68.9k
tail_call:
1457
68.9k
    if (first >= afterLast) {
1458
578
        if (!URI_FUNC(OnExitSegmentNzNcOrScheme2)(state, first, memory)) {
1459
0
            URI_FUNC(StopMalloc)(state, memory);
1460
0
            return NULL;
1461
0
        }
1462
578
        return afterLast;
1463
578
    }
1464
1465
68.4k
    switch (*first) {
1466
194
    case _UT('.'):
1467
388
    case _UT('+'):
1468
583
    case _UT('-'):
1469
2.58M
    case URI_SET_ALPHA(_UT):
1470
2.58M
    case URI_SET_DIGIT(_UT):
1471
68.1k
        first += 1;
1472
68.1k
        goto tail_call;
1473
1474
5
    case _UT('%'): {
1475
5
        const URI_CHAR * const afterPctEncoded =
1476
5
                URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1477
5
        if (afterPctEncoded == NULL) {
1478
1
            return NULL;
1479
1
        }
1480
4
        return URI_FUNC(ParseMustBeSegmentNzNc)(
1481
4
                state, afterPctEncoded, afterLast, memory);
1482
5
    }
1483
1484
1
    case _UT('!'):
1485
3
    case _UT('$'):
1486
4
    case _UT('&'):
1487
5
    case _UT('('):
1488
6
    case _UT(')'):
1489
7
    case _UT('*'):
1490
8
    case _UT(','):
1491
10
    case _UT(';'):
1492
12
    case _UT('@'):
1493
13
    case _UT('_'):
1494
15
    case _UT('~'):
1495
16
    case _UT('='):
1496
17
    case _UT('\''):
1497
17
        return URI_FUNC(ParseMustBeSegmentNzNc)(state, first + 1, afterLast, memory);
1498
1499
136
    case _UT('/'): {
1500
136
        const URI_CHAR * afterZeroMoreSlashSegs;
1501
136
        const URI_CHAR * const afterSegment =
1502
136
                URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory);
1503
136
        if (afterSegment == NULL) {
1504
3
            return NULL;
1505
3
        }
1506
133
        if (!URI_FUNC(PushPathSegment)(
1507
133
                    state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
1508
0
            URI_FUNC(StopMalloc)(state, memory);
1509
0
            return NULL;
1510
0
        }
1511
133
        state->uri->scheme.first = NULL; /* Not a scheme, reset */
1512
133
        if (!URI_FUNC(PushPathSegment)(
1513
133
                    state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */
1514
0
            URI_FUNC(StopMalloc)(state, memory);
1515
0
            return NULL;
1516
0
        }
1517
133
        afterZeroMoreSlashSegs =
1518
133
                URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegment, afterLast, memory);
1519
133
        if (afterZeroMoreSlashSegs == NULL) {
1520
1
            return NULL;
1521
1
        }
1522
132
        return URI_FUNC(ParseUriTail)(state, afterZeroMoreSlashSegs, afterLast, memory);
1523
133
    }
1524
1525
116
    case _UT(':'): {
1526
116
        const URI_CHAR * const afterHierPart =
1527
116
                URI_FUNC(ParseHierPart)(state, first + 1, afterLast, memory);
1528
116
        state->uri->scheme.afterLast = first; /* SCHEME END */
1529
116
        if (afterHierPart == NULL) {
1530
3
            return NULL;
1531
3
        }
1532
113
        return URI_FUNC(ParseUriTail)(state, afterHierPart, afterLast, memory);
1533
116
    }
1534
1535
6
    default:
1536
6
        if (!URI_FUNC(OnExitSegmentNzNcOrScheme2)(state, first, memory)) {
1537
0
            URI_FUNC(StopMalloc)(state, memory);
1538
0
            return NULL;
1539
0
        }
1540
6
        return URI_FUNC(ParseUriTail)(state, first, afterLast, memory);
1541
68.4k
    }
1542
68.4k
}
UriParse.c:uriParseSegmentNzNcOrScheme2A
Line
Count
Source
1455
858
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1456
68.9k
tail_call:
1457
68.9k
    if (first >= afterLast) {
1458
578
        if (!URI_FUNC(OnExitSegmentNzNcOrScheme2)(state, first, memory)) {
1459
0
            URI_FUNC(StopMalloc)(state, memory);
1460
0
            return NULL;
1461
0
        }
1462
578
        return afterLast;
1463
578
    }
1464
1465
68.4k
    switch (*first) {
1466
194
    case _UT('.'):
1467
388
    case _UT('+'):
1468
583
    case _UT('-'):
1469
2.58M
    case URI_SET_ALPHA(_UT):
1470
2.58M
    case URI_SET_DIGIT(_UT):
1471
68.1k
        first += 1;
1472
68.1k
        goto tail_call;
1473
1474
5
    case _UT('%'): {
1475
5
        const URI_CHAR * const afterPctEncoded =
1476
5
                URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1477
5
        if (afterPctEncoded == NULL) {
1478
1
            return NULL;
1479
1
        }
1480
4
        return URI_FUNC(ParseMustBeSegmentNzNc)(
1481
4
                state, afterPctEncoded, afterLast, memory);
1482
5
    }
1483
1484
1
    case _UT('!'):
1485
3
    case _UT('$'):
1486
4
    case _UT('&'):
1487
5
    case _UT('('):
1488
6
    case _UT(')'):
1489
7
    case _UT('*'):
1490
8
    case _UT(','):
1491
10
    case _UT(';'):
1492
12
    case _UT('@'):
1493
13
    case _UT('_'):
1494
15
    case _UT('~'):
1495
16
    case _UT('='):
1496
17
    case _UT('\''):
1497
17
        return URI_FUNC(ParseMustBeSegmentNzNc)(state, first + 1, afterLast, memory);
1498
1499
136
    case _UT('/'): {
1500
136
        const URI_CHAR * afterZeroMoreSlashSegs;
1501
136
        const URI_CHAR * const afterSegment =
1502
136
                URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory);
1503
136
        if (afterSegment == NULL) {
1504
3
            return NULL;
1505
3
        }
1506
133
        if (!URI_FUNC(PushPathSegment)(
1507
133
                    state, state->uri->scheme.first, first, memory)) { /* SEGMENT BOTH */
1508
0
            URI_FUNC(StopMalloc)(state, memory);
1509
0
            return NULL;
1510
0
        }
1511
133
        state->uri->scheme.first = NULL; /* Not a scheme, reset */
1512
133
        if (!URI_FUNC(PushPathSegment)(
1513
133
                    state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */
1514
0
            URI_FUNC(StopMalloc)(state, memory);
1515
0
            return NULL;
1516
0
        }
1517
133
        afterZeroMoreSlashSegs =
1518
133
                URI_FUNC(ParseZeroMoreSlashSegs)(state, afterSegment, afterLast, memory);
1519
133
        if (afterZeroMoreSlashSegs == NULL) {
1520
1
            return NULL;
1521
1
        }
1522
132
        return URI_FUNC(ParseUriTail)(state, afterZeroMoreSlashSegs, afterLast, memory);
1523
133
    }
1524
1525
116
    case _UT(':'): {
1526
116
        const URI_CHAR * const afterHierPart =
1527
116
                URI_FUNC(ParseHierPart)(state, first + 1, afterLast, memory);
1528
116
        state->uri->scheme.afterLast = first; /* SCHEME END */
1529
116
        if (afterHierPart == NULL) {
1530
3
            return NULL;
1531
3
        }
1532
113
        return URI_FUNC(ParseUriTail)(state, afterHierPart, afterLast, memory);
1533
116
    }
1534
1535
6
    default:
1536
6
        if (!URI_FUNC(OnExitSegmentNzNcOrScheme2)(state, first, memory)) {
1537
0
            URI_FUNC(StopMalloc)(state, memory);
1538
0
            return NULL;
1539
0
        }
1540
6
        return URI_FUNC(ParseUriTail)(state, first, afterLast, memory);
1541
68.4k
    }
1542
68.4k
}
Unexecuted instantiation: UriParse.c:uriParseSegmentNzNcOrScheme2W
1543
1544
/*
1545
 * [uriReference]->[ALPHA][segmentNzNcOrScheme2]
1546
 * [uriReference]->[DIGIT][mustBeSegmentNzNc]
1547
 * [uriReference]->[pctEncoded][mustBeSegmentNzNc]
1548
 * [uriReference]->[subDelims][mustBeSegmentNzNc]
1549
 * [uriReference]->[uriTail] // can take <NULL>
1550
 * [uriReference]-><.>[mustBeSegmentNzNc]
1551
 * [uriReference]-></>[partHelperTwo][uriTail]
1552
 * [uriReference]-><@>[mustBeSegmentNzNc]
1553
 * [uriReference]-><_>[mustBeSegmentNzNc]
1554
 * [uriReference]-><~>[mustBeSegmentNzNc]
1555
 * [uriReference]-><->[mustBeSegmentNzNc]
1556
 */
1557
static const URI_CHAR * URI_FUNC(ParseUriReference)(URI_TYPE(ParserState) * state,
1558
7.03k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1559
7.03k
    if (first >= afterLast) {
1560
1
        return afterLast;
1561
1
    }
1562
1563
7.03k
    switch (*first) {
1564
21.7k
    case URI_SET_ALPHA(_UT):
1565
858
        state->uri->scheme.first = first; /* SCHEME BEGIN */
1566
858
        return URI_FUNC(ParseSegmentNzNcOrScheme2)(state, first + 1, afterLast, memory);
1567
1568
1.56k
    case URI_SET_DIGIT(_UT):
1569
4.94k
    case URI_SET_SUB_DELIMS(_UT):
1570
4.94k
    case _UT('.'):
1571
704
    case _UT('_'):
1572
746
    case _UT('~'):
1573
781
    case _UT('-'):
1574
814
    case _UT('@'):
1575
814
        state->uri->scheme.first = first; /* SEGMENT BEGIN, ABUSE SCHEME POINTER */
1576
814
        return URI_FUNC(ParseMustBeSegmentNzNc)(state, first + 1, afterLast, memory);
1577
1578
372
    case _UT('%'): {
1579
372
        const URI_CHAR * const afterPctEncoded =
1580
372
                URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1581
372
        if (afterPctEncoded == NULL) {
1582
26
            return NULL;
1583
26
        }
1584
346
        state->uri->scheme.first = first; /* SEGMENT BEGIN, ABUSE SCHEME POINTER */
1585
346
        return URI_FUNC(ParseMustBeSegmentNzNc)(
1586
346
                state, afterPctEncoded, afterLast, memory);
1587
372
    }
1588
1589
4.31k
    case _UT('/'): {
1590
4.31k
        const URI_CHAR * const afterPartHelperTwo =
1591
4.31k
                URI_FUNC(ParsePartHelperTwo)(state, first + 1, afterLast, memory);
1592
4.31k
        if (afterPartHelperTwo == NULL) {
1593
2.03k
            return NULL;
1594
2.03k
        }
1595
2.28k
        return URI_FUNC(ParseUriTail)(state, afterPartHelperTwo, afterLast, memory);
1596
4.31k
    }
1597
1598
681
    default:
1599
681
        return URI_FUNC(ParseUriTail)(state, first, afterLast, memory);
1600
7.03k
    }
1601
7.03k
}
UriParse.c:uriParseUriReferenceA
Line
Count
Source
1558
7.03k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1559
7.03k
    if (first >= afterLast) {
1560
1
        return afterLast;
1561
1
    }
1562
1563
7.03k
    switch (*first) {
1564
858
    case URI_SET_ALPHA(_UT):
1565
858
        state->uri->scheme.first = first; /* SCHEME BEGIN */
1566
858
        return URI_FUNC(ParseSegmentNzNcOrScheme2)(state, first + 1, afterLast, memory);
1567
1568
1.56k
    case URI_SET_DIGIT(_UT):
1569
4.94k
    case URI_SET_SUB_DELIMS(_UT):
1570
4.94k
    case _UT('.'):
1571
704
    case _UT('_'):
1572
746
    case _UT('~'):
1573
781
    case _UT('-'):
1574
814
    case _UT('@'):
1575
814
        state->uri->scheme.first = first; /* SEGMENT BEGIN, ABUSE SCHEME POINTER */
1576
814
        return URI_FUNC(ParseMustBeSegmentNzNc)(state, first + 1, afterLast, memory);
1577
1578
372
    case _UT('%'): {
1579
372
        const URI_CHAR * const afterPctEncoded =
1580
372
                URI_FUNC(ParsePctEncoded)(state, first, afterLast, memory);
1581
372
        if (afterPctEncoded == NULL) {
1582
26
            return NULL;
1583
26
        }
1584
346
        state->uri->scheme.first = first; /* SEGMENT BEGIN, ABUSE SCHEME POINTER */
1585
346
        return URI_FUNC(ParseMustBeSegmentNzNc)(
1586
346
                state, afterPctEncoded, afterLast, memory);
1587
372
    }
1588
1589
4.31k
    case _UT('/'): {
1590
4.31k
        const URI_CHAR * const afterPartHelperTwo =
1591
4.31k
                URI_FUNC(ParsePartHelperTwo)(state, first + 1, afterLast, memory);
1592
4.31k
        if (afterPartHelperTwo == NULL) {
1593
2.03k
            return NULL;
1594
2.03k
        }
1595
2.28k
        return URI_FUNC(ParseUriTail)(state, afterPartHelperTwo, afterLast, memory);
1596
4.31k
    }
1597
1598
681
    default:
1599
681
        return URI_FUNC(ParseUriTail)(state, first, afterLast, memory);
1600
7.03k
    }
1601
7.03k
}
Unexecuted instantiation: UriParse.c:uriParseUriReferenceW
1602
1603
/*
1604
 * [uriTail]-><#>[queryFrag]
1605
 * [uriTail]-><?>[queryFrag][uriTailTwo]
1606
 * [uriTail]-><NULL>
1607
 */
1608
static URI_INLINE const URI_CHAR * URI_FUNC(ParseUriTail)(URI_TYPE(ParserState) * state,
1609
3.36k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1610
3.36k
    if (first >= afterLast) {
1611
2.54k
        return afterLast;
1612
2.54k
    }
1613
1614
823
    switch (*first) {
1615
320
    case _UT('#'): {
1616
320
        const URI_CHAR * const afterQueryFrag =
1617
320
                URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory);
1618
320
        if (afterQueryFrag == NULL) {
1619
2
            return NULL;
1620
2
        }
1621
318
        state->uri->fragment.first = first + 1; /* FRAGMENT BEGIN */
1622
318
        state->uri->fragment.afterLast = afterQueryFrag; /* FRAGMENT END */
1623
318
        return afterQueryFrag;
1624
320
    }
1625
1626
372
    case _UT('?'): {
1627
372
        const URI_CHAR * const afterQueryFrag =
1628
372
                URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory);
1629
372
        if (afterQueryFrag == NULL) {
1630
9
            return NULL;
1631
9
        }
1632
363
        state->uri->query.first = first + 1; /* QUERY BEGIN */
1633
363
        state->uri->query.afterLast = afterQueryFrag; /* QUERY END */
1634
363
        return URI_FUNC(ParseUriTailTwo)(state, afterQueryFrag, afterLast, memory);
1635
372
    }
1636
1637
131
    default:
1638
131
        return first;
1639
823
    }
1640
823
}
UriParse.c:uriParseUriTailA
Line
Count
Source
1609
3.36k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1610
3.36k
    if (first >= afterLast) {
1611
2.54k
        return afterLast;
1612
2.54k
    }
1613
1614
823
    switch (*first) {
1615
320
    case _UT('#'): {
1616
320
        const URI_CHAR * const afterQueryFrag =
1617
320
                URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory);
1618
320
        if (afterQueryFrag == NULL) {
1619
2
            return NULL;
1620
2
        }
1621
318
        state->uri->fragment.first = first + 1; /* FRAGMENT BEGIN */
1622
318
        state->uri->fragment.afterLast = afterQueryFrag; /* FRAGMENT END */
1623
318
        return afterQueryFrag;
1624
320
    }
1625
1626
372
    case _UT('?'): {
1627
372
        const URI_CHAR * const afterQueryFrag =
1628
372
                URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory);
1629
372
        if (afterQueryFrag == NULL) {
1630
9
            return NULL;
1631
9
        }
1632
363
        state->uri->query.first = first + 1; /* QUERY BEGIN */
1633
363
        state->uri->query.afterLast = afterQueryFrag; /* QUERY END */
1634
363
        return URI_FUNC(ParseUriTailTwo)(state, afterQueryFrag, afterLast, memory);
1635
372
    }
1636
1637
131
    default:
1638
131
        return first;
1639
823
    }
1640
823
}
Unexecuted instantiation: UriParse.c:uriParseUriTailW
1641
1642
/*
1643
 * [uriTailTwo]-><#>[queryFrag]
1644
 * [uriTailTwo]-><NULL>
1645
 */
1646
static URI_INLINE const URI_CHAR * URI_FUNC(ParseUriTailTwo)(
1647
        URI_TYPE(ParserState) * state, const URI_CHAR * first, const URI_CHAR * afterLast,
1648
363
        UriMemoryManager * memory) {
1649
363
    if (first >= afterLast) {
1650
346
        return afterLast;
1651
346
    }
1652
1653
17
    switch (*first) {
1654
3
    case _UT('#'): {
1655
3
        const URI_CHAR * const afterQueryFrag =
1656
3
                URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory);
1657
3
        if (afterQueryFrag == NULL) {
1658
1
            return NULL;
1659
1
        }
1660
2
        state->uri->fragment.first = first + 1; /* FRAGMENT BEGIN */
1661
2
        state->uri->fragment.afterLast = afterQueryFrag; /* FRAGMENT END */
1662
2
        return afterQueryFrag;
1663
3
    }
1664
1665
14
    default:
1666
14
        return first;
1667
17
    }
1668
17
}
UriParse.c:uriParseUriTailTwoA
Line
Count
Source
1648
363
        UriMemoryManager * memory) {
1649
363
    if (first >= afterLast) {
1650
346
        return afterLast;
1651
346
    }
1652
1653
17
    switch (*first) {
1654
3
    case _UT('#'): {
1655
3
        const URI_CHAR * const afterQueryFrag =
1656
3
                URI_FUNC(ParseQueryFrag)(state, first + 1, afterLast, memory);
1657
3
        if (afterQueryFrag == NULL) {
1658
1
            return NULL;
1659
1
        }
1660
2
        state->uri->fragment.first = first + 1; /* FRAGMENT BEGIN */
1661
2
        state->uri->fragment.afterLast = afterQueryFrag; /* FRAGMENT END */
1662
2
        return afterQueryFrag;
1663
3
    }
1664
1665
14
    default:
1666
14
        return first;
1667
17
    }
1668
17
}
Unexecuted instantiation: UriParse.c:uriParseUriTailTwoW
1669
1670
/*
1671
 * [zeroMoreSlashSegs]-></>[segment][zeroMoreSlashSegs]
1672
 * [zeroMoreSlashSegs]-><NULL>
1673
 */
1674
static const URI_CHAR * URI_FUNC(ParseZeroMoreSlashSegs)(URI_TYPE(ParserState) * state,
1675
1.01k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1676
4.85k
tail_call:
1677
4.85k
    if (first >= afterLast) {
1678
965
        return afterLast;
1679
965
    }
1680
1681
3.88k
    switch (*first) {
1682
3.84k
    case _UT('/'): {
1683
3.84k
        const URI_CHAR * const afterSegment =
1684
3.84k
                URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory);
1685
3.84k
        if (afterSegment == NULL) {
1686
4
            return NULL;
1687
4
        }
1688
3.84k
        if (!URI_FUNC(PushPathSegment)(
1689
3.84k
                    state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */
1690
0
            URI_FUNC(StopMalloc)(state, memory);
1691
0
            return NULL;
1692
0
        }
1693
3.84k
        first = afterSegment;
1694
3.84k
        goto tail_call;
1695
3.84k
    }
1696
1697
44
    default:
1698
44
        return first;
1699
3.88k
    }
1700
3.88k
}
UriParse.c:uriParseZeroMoreSlashSegsA
Line
Count
Source
1675
1.01k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1676
4.85k
tail_call:
1677
4.85k
    if (first >= afterLast) {
1678
965
        return afterLast;
1679
965
    }
1680
1681
3.88k
    switch (*first) {
1682
3.84k
    case _UT('/'): {
1683
3.84k
        const URI_CHAR * const afterSegment =
1684
3.84k
                URI_FUNC(ParseSegment)(state, first + 1, afterLast, memory);
1685
3.84k
        if (afterSegment == NULL) {
1686
4
            return NULL;
1687
4
        }
1688
3.84k
        if (!URI_FUNC(PushPathSegment)(
1689
3.84k
                    state, first + 1, afterSegment, memory)) { /* SEGMENT BOTH */
1690
0
            URI_FUNC(StopMalloc)(state, memory);
1691
0
            return NULL;
1692
0
        }
1693
3.84k
        first = afterSegment;
1694
3.84k
        goto tail_call;
1695
3.84k
    }
1696
1697
44
    default:
1698
44
        return first;
1699
3.88k
    }
1700
3.88k
}
Unexecuted instantiation: UriParse.c:uriParseZeroMoreSlashSegsW
1701
1702
static URI_INLINE void URI_FUNC(ResetParserStateExceptUri)(
1703
7.03k
        URI_TYPE(ParserState) * state) {
1704
7.03k
    URI_TYPE(Uri) * const uriBackup = state->uri;
1705
7.03k
    memset(state, 0, sizeof(URI_TYPE(ParserState)));
1706
7.03k
    state->uri = uriBackup;
1707
7.03k
}
UriParse.c:uriResetParserStateExceptUriA
Line
Count
Source
1703
7.03k
        URI_TYPE(ParserState) * state) {
1704
7.03k
    URI_TYPE(Uri) * const uriBackup = state->uri;
1705
7.03k
    memset(state, 0, sizeof(URI_TYPE(ParserState)));
1706
7.03k
    state->uri = uriBackup;
1707
7.03k
}
Unexecuted instantiation: UriParse.c:uriResetParserStateExceptUriW
1708
1709
static URI_INLINE UriBool URI_FUNC(PushPathSegment)(URI_TYPE(ParserState) * state,
1710
7.19k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1711
7.19k
    URI_TYPE(PathSegment) * segment =
1712
7.19k
            memory->calloc(memory, 1, sizeof(URI_TYPE(PathSegment)));
1713
7.19k
    if (segment == NULL) {
1714
0
        return URI_FALSE; /* Raises malloc error */
1715
0
    }
1716
7.19k
    if (first == afterLast) {
1717
1.99k
        segment->text.first = URI_FUNC(SafeToPointTo);
1718
1.99k
        segment->text.afterLast = URI_FUNC(SafeToPointTo);
1719
5.20k
    } else {
1720
5.20k
        segment->text.first = first;
1721
5.20k
        segment->text.afterLast = afterLast;
1722
5.20k
    }
1723
1724
    /* First segment ever? */
1725
7.19k
    if (state->uri->pathHead == NULL) {
1726
        /* First segment ever, set head and tail */
1727
2.49k
        state->uri->pathHead = segment;
1728
2.49k
        state->uri->pathTail = segment;
1729
4.69k
    } else {
1730
        /* Append, update tail */
1731
4.69k
        state->uri->pathTail->next = segment;
1732
4.69k
        state->uri->pathTail = segment;
1733
4.69k
    }
1734
1735
7.19k
    return URI_TRUE; /* Success */
1736
7.19k
}
UriParse.c:uriPushPathSegmentA
Line
Count
Source
1710
7.19k
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
1711
7.19k
    URI_TYPE(PathSegment) * segment =
1712
7.19k
            memory->calloc(memory, 1, sizeof(URI_TYPE(PathSegment)));
1713
7.19k
    if (segment == NULL) {
1714
0
        return URI_FALSE; /* Raises malloc error */
1715
0
    }
1716
7.19k
    if (first == afterLast) {
1717
1.99k
        segment->text.first = URI_FUNC(SafeToPointTo);
1718
1.99k
        segment->text.afterLast = URI_FUNC(SafeToPointTo);
1719
5.20k
    } else {
1720
5.20k
        segment->text.first = first;
1721
5.20k
        segment->text.afterLast = afterLast;
1722
5.20k
    }
1723
1724
    /* First segment ever? */
1725
7.19k
    if (state->uri->pathHead == NULL) {
1726
        /* First segment ever, set head and tail */
1727
2.49k
        state->uri->pathHead = segment;
1728
2.49k
        state->uri->pathTail = segment;
1729
4.69k
    } else {
1730
        /* Append, update tail */
1731
4.69k
        state->uri->pathTail->next = segment;
1732
4.69k
        state->uri->pathTail = segment;
1733
4.69k
    }
1734
1735
7.19k
    return URI_TRUE; /* Success */
1736
7.19k
}
Unexecuted instantiation: UriParse.c:uriPushPathSegmentW
1737
1738
int URI_FUNC(ParseUriEx)(URI_TYPE(ParserState) * state, const URI_CHAR * first,
1739
7.03k
        const URI_CHAR * afterLast) {
1740
7.03k
    return URI_FUNC(ParseUriExMm)(state, first, afterLast, NULL);
1741
7.03k
}
uriParseUriExA
Line
Count
Source
1739
7.03k
        const URI_CHAR * afterLast) {
1740
7.03k
    return URI_FUNC(ParseUriExMm)(state, first, afterLast, NULL);
1741
7.03k
}
Unexecuted instantiation: uriParseUriExW
1742
1743
static int URI_FUNC(ParseUriExMm)(URI_TYPE(ParserState) * state, const URI_CHAR * first,
1744
7.03k
        const URI_CHAR * afterLast, UriMemoryManager * memory) {
1745
7.03k
    const URI_CHAR * afterUriReference;
1746
7.03k
    URI_TYPE(Uri) * uri;
1747
1748
    /* Check params */
1749
7.03k
    if ((state == NULL) || (first == NULL) || (afterLast == NULL)) {
1750
0
        return URI_ERROR_NULL;
1751
0
    }
1752
7.03k
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
1753
1754
7.03k
    uri = state->uri;
1755
1756
    /* Init parser */
1757
7.03k
    URI_FUNC(ResetParserStateExceptUri)(state);
1758
7.03k
    URI_FUNC(ResetUri)(uri);
1759
1760
    /* Parse */
1761
7.03k
    afterUriReference = URI_FUNC(ParseUriReference)(state, first, afterLast, memory);
1762
7.03k
    if (afterUriReference == NULL) {
1763
        /* Waterproof errorPos <= afterLast */
1764
2.24k
        if (state->errorPos && (state->errorPos > afterLast)) {
1765
0
            state->errorPos = afterLast;
1766
0
        }
1767
2.24k
        return state->errorCode;
1768
2.24k
    }
1769
4.79k
    if (afterUriReference != afterLast) {
1770
148
        if (afterUriReference < afterLast) {
1771
148
            URI_FUNC(StopSyntax)(state, afterUriReference, memory);
1772
148
        } else {
1773
0
            URI_FUNC(StopSyntax)(state, afterLast, memory);
1774
0
        }
1775
148
        return state->errorCode;
1776
148
    }
1777
4.64k
    return URI_SUCCESS;
1778
4.79k
}
UriParse.c:uriParseUriExMmA
Line
Count
Source
1744
7.03k
        const URI_CHAR * afterLast, UriMemoryManager * memory) {
1745
7.03k
    const URI_CHAR * afterUriReference;
1746
7.03k
    URI_TYPE(Uri) * uri;
1747
1748
    /* Check params */
1749
7.03k
    if ((state == NULL) || (first == NULL) || (afterLast == NULL)) {
1750
0
        return URI_ERROR_NULL;
1751
0
    }
1752
7.03k
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
1753
1754
7.03k
    uri = state->uri;
1755
1756
    /* Init parser */
1757
7.03k
    URI_FUNC(ResetParserStateExceptUri)(state);
1758
7.03k
    URI_FUNC(ResetUri)(uri);
1759
1760
    /* Parse */
1761
7.03k
    afterUriReference = URI_FUNC(ParseUriReference)(state, first, afterLast, memory);
1762
7.03k
    if (afterUriReference == NULL) {
1763
        /* Waterproof errorPos <= afterLast */
1764
2.24k
        if (state->errorPos && (state->errorPos > afterLast)) {
1765
0
            state->errorPos = afterLast;
1766
0
        }
1767
2.24k
        return state->errorCode;
1768
2.24k
    }
1769
4.79k
    if (afterUriReference != afterLast) {
1770
148
        if (afterUriReference < afterLast) {
1771
148
            URI_FUNC(StopSyntax)(state, afterUriReference, memory);
1772
148
        } else {
1773
0
            URI_FUNC(StopSyntax)(state, afterLast, memory);
1774
0
        }
1775
148
        return state->errorCode;
1776
148
    }
1777
4.64k
    return URI_SUCCESS;
1778
4.79k
}
Unexecuted instantiation: UriParse.c:uriParseUriExMmW
1779
1780
7.03k
int URI_FUNC(ParseUri)(URI_TYPE(ParserState) * state, const URI_CHAR * text) {
1781
7.03k
    if ((state == NULL) || (text == NULL)) {
1782
0
        return URI_ERROR_NULL;
1783
0
    }
1784
7.03k
    return URI_FUNC(ParseUriEx)(state, text, text + URI_STRLEN(text));
1785
7.03k
}
uriParseUriA
Line
Count
Source
1780
7.03k
int URI_FUNC(ParseUri)(URI_TYPE(ParserState) * state, const URI_CHAR * text) {
1781
7.03k
    if ((state == NULL) || (text == NULL)) {
1782
0
        return URI_ERROR_NULL;
1783
0
    }
1784
7.03k
    return URI_FUNC(ParseUriEx)(state, text, text + URI_STRLEN(text));
1785
7.03k
}
Unexecuted instantiation: uriParseUriW
1786
1787
int URI_FUNC(ParseSingleUri)(
1788
0
        URI_TYPE(Uri) * uri, const URI_CHAR * text, const URI_CHAR ** errorPos) {
1789
0
    return URI_FUNC(ParseSingleUriEx)(uri, text, NULL, errorPos);
1790
0
}
Unexecuted instantiation: uriParseSingleUriA
Unexecuted instantiation: uriParseSingleUriW
1791
1792
int URI_FUNC(ParseSingleUriEx)(URI_TYPE(Uri) * uri, const URI_CHAR * first,
1793
0
        const URI_CHAR * afterLast, const URI_CHAR ** errorPos) {
1794
0
    if ((afterLast == NULL) && (first != NULL)) {
1795
0
        afterLast = first + URI_STRLEN(first);
1796
0
    }
1797
0
    return URI_FUNC(ParseSingleUriExMm)(uri, first, afterLast, errorPos, NULL);
1798
0
}
Unexecuted instantiation: uriParseSingleUriExA
Unexecuted instantiation: uriParseSingleUriExW
1799
1800
int URI_FUNC(ParseSingleUriExMm)(URI_TYPE(Uri) * uri, const URI_CHAR * first,
1801
        const URI_CHAR * afterLast, const URI_CHAR ** errorPos,
1802
0
        UriMemoryManager * memory) {
1803
0
    URI_TYPE(ParserState) state;
1804
0
    int res;
1805
1806
    /* Check params */
1807
0
    if ((uri == NULL) || (first == NULL) || (afterLast == NULL)) {
1808
0
        return URI_ERROR_NULL;
1809
0
    }
1810
0
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
1811
1812
0
    state.uri = uri;
1813
1814
0
    res = URI_FUNC(ParseUriExMm)(&state, first, afterLast, memory);
1815
1816
0
    if (res != URI_SUCCESS) {
1817
0
        if (errorPos != NULL) {
1818
0
            *errorPos = state.errorPos;
1819
0
        }
1820
0
        URI_FUNC(FreeUriMembersMm)(uri, memory);
1821
0
    }
1822
1823
0
    return res;
1824
0
}
Unexecuted instantiation: uriParseSingleUriExMmA
Unexecuted instantiation: uriParseSingleUriExMmW
1825
1826
7.03k
void URI_FUNC(FreeUriMembers)(URI_TYPE(Uri) * uri) {
1827
7.03k
    URI_FUNC(FreeUriMembersMm)(uri, NULL);
1828
7.03k
}
uriFreeUriMembersA
Line
Count
Source
1826
7.03k
void URI_FUNC(FreeUriMembers)(URI_TYPE(Uri) * uri) {
1827
7.03k
    URI_FUNC(FreeUriMembersMm)(uri, NULL);
1828
7.03k
}
Unexecuted instantiation: uriFreeUriMembersW
1829
1830
9.43k
int URI_FUNC(FreeUriMembersMm)(URI_TYPE(Uri) * uri, UriMemoryManager * memory) {
1831
9.43k
    if (uri == NULL) {
1832
0
        return URI_ERROR_NULL;
1833
0
    }
1834
1835
9.43k
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
1836
1837
9.43k
    if (uri->owner) {
1838
        /* Scheme */
1839
0
        if (uri->scheme.first != NULL) {
1840
0
            if (uri->scheme.first != uri->scheme.afterLast) {
1841
0
                memory->free(memory, (URI_CHAR *)uri->scheme.first);
1842
0
            }
1843
0
            uri->scheme.first = NULL;
1844
0
            uri->scheme.afterLast = NULL;
1845
0
        }
1846
1847
        /* User info */
1848
0
        if (uri->userInfo.first != NULL) {
1849
0
            if (uri->userInfo.first != uri->userInfo.afterLast) {
1850
0
                memory->free(memory, (URI_CHAR *)uri->userInfo.first);
1851
0
            }
1852
0
            uri->userInfo.first = NULL;
1853
0
            uri->userInfo.afterLast = NULL;
1854
0
        }
1855
1856
        /* Host data - IPvFuture (may affect host text) */
1857
0
        if (uri->hostData.ipFuture.first != NULL) {
1858
            /* NOTE: .hostData.ipFuture holds the very same range pointers
1859
             *       as .hostText; we must not free memory twice. */
1860
0
            uri->hostText.first = NULL;
1861
0
            uri->hostText.afterLast = NULL;
1862
1863
0
            if (uri->hostData.ipFuture.first != uri->hostData.ipFuture.afterLast) {
1864
0
                memory->free(memory, (URI_CHAR *)uri->hostData.ipFuture.first);
1865
0
            }
1866
0
            uri->hostData.ipFuture.first = NULL;
1867
0
            uri->hostData.ipFuture.afterLast = NULL;
1868
0
        }
1869
1870
        /* Host text (after IPvFuture, see above) */
1871
0
        if (uri->hostText.first != NULL) {
1872
0
            if (uri->hostText.first != uri->hostText.afterLast) {
1873
0
                memory->free(memory, (URI_CHAR *)uri->hostText.first);
1874
0
            }
1875
0
            uri->hostText.first = NULL;
1876
0
            uri->hostText.afterLast = NULL;
1877
0
        }
1878
0
    }
1879
1880
    /* Host data - IPv4 */
1881
9.43k
    if (uri->hostData.ip4 != NULL) {
1882
26
        memory->free(memory, uri->hostData.ip4);
1883
26
        uri->hostData.ip4 = NULL;
1884
26
    }
1885
1886
    /* Host data - IPv6 */
1887
9.43k
    if (uri->hostData.ip6 != NULL) {
1888
492
        memory->free(memory, uri->hostData.ip6);
1889
492
        uri->hostData.ip6 = NULL;
1890
492
    }
1891
1892
    /* Port text */
1893
9.43k
    if (uri->owner && (uri->portText.first != NULL)) {
1894
0
        if (uri->portText.first != uri->portText.afterLast) {
1895
0
            memory->free(memory, (URI_CHAR *)uri->portText.first);
1896
0
        }
1897
0
        uri->portText.first = NULL;
1898
0
        uri->portText.afterLast = NULL;
1899
0
    }
1900
1901
    /* Path */
1902
9.43k
    URI_FUNC(FreeUriPath)(uri, memory);
1903
1904
9.43k
    if (uri->owner) {
1905
        /* Query */
1906
0
        if (uri->query.first != NULL) {
1907
0
            if (uri->query.first != uri->query.afterLast) {
1908
0
                memory->free(memory, (URI_CHAR *)uri->query.first);
1909
0
            }
1910
0
            uri->query.first = NULL;
1911
0
            uri->query.afterLast = NULL;
1912
0
        }
1913
1914
        /* Fragment */
1915
0
        if (uri->fragment.first != NULL) {
1916
0
            if (uri->fragment.first != uri->fragment.afterLast) {
1917
0
                memory->free(memory, (URI_CHAR *)uri->fragment.first);
1918
0
            }
1919
0
            uri->fragment.first = NULL;
1920
0
            uri->fragment.afterLast = NULL;
1921
0
        }
1922
0
    }
1923
1924
9.43k
    return URI_SUCCESS;
1925
9.43k
}
uriFreeUriMembersMmA
Line
Count
Source
1830
9.43k
int URI_FUNC(FreeUriMembersMm)(URI_TYPE(Uri) * uri, UriMemoryManager * memory) {
1831
9.43k
    if (uri == NULL) {
1832
0
        return URI_ERROR_NULL;
1833
0
    }
1834
1835
9.43k
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
1836
1837
9.43k
    if (uri->owner) {
1838
        /* Scheme */
1839
0
        if (uri->scheme.first != NULL) {
1840
0
            if (uri->scheme.first != uri->scheme.afterLast) {
1841
0
                memory->free(memory, (URI_CHAR *)uri->scheme.first);
1842
0
            }
1843
0
            uri->scheme.first = NULL;
1844
0
            uri->scheme.afterLast = NULL;
1845
0
        }
1846
1847
        /* User info */
1848
0
        if (uri->userInfo.first != NULL) {
1849
0
            if (uri->userInfo.first != uri->userInfo.afterLast) {
1850
0
                memory->free(memory, (URI_CHAR *)uri->userInfo.first);
1851
0
            }
1852
0
            uri->userInfo.first = NULL;
1853
0
            uri->userInfo.afterLast = NULL;
1854
0
        }
1855
1856
        /* Host data - IPvFuture (may affect host text) */
1857
0
        if (uri->hostData.ipFuture.first != NULL) {
1858
            /* NOTE: .hostData.ipFuture holds the very same range pointers
1859
             *       as .hostText; we must not free memory twice. */
1860
0
            uri->hostText.first = NULL;
1861
0
            uri->hostText.afterLast = NULL;
1862
1863
0
            if (uri->hostData.ipFuture.first != uri->hostData.ipFuture.afterLast) {
1864
0
                memory->free(memory, (URI_CHAR *)uri->hostData.ipFuture.first);
1865
0
            }
1866
0
            uri->hostData.ipFuture.first = NULL;
1867
0
            uri->hostData.ipFuture.afterLast = NULL;
1868
0
        }
1869
1870
        /* Host text (after IPvFuture, see above) */
1871
0
        if (uri->hostText.first != NULL) {
1872
0
            if (uri->hostText.first != uri->hostText.afterLast) {
1873
0
                memory->free(memory, (URI_CHAR *)uri->hostText.first);
1874
0
            }
1875
0
            uri->hostText.first = NULL;
1876
0
            uri->hostText.afterLast = NULL;
1877
0
        }
1878
0
    }
1879
1880
    /* Host data - IPv4 */
1881
9.43k
    if (uri->hostData.ip4 != NULL) {
1882
26
        memory->free(memory, uri->hostData.ip4);
1883
26
        uri->hostData.ip4 = NULL;
1884
26
    }
1885
1886
    /* Host data - IPv6 */
1887
9.43k
    if (uri->hostData.ip6 != NULL) {
1888
492
        memory->free(memory, uri->hostData.ip6);
1889
492
        uri->hostData.ip6 = NULL;
1890
492
    }
1891
1892
    /* Port text */
1893
9.43k
    if (uri->owner && (uri->portText.first != NULL)) {
1894
0
        if (uri->portText.first != uri->portText.afterLast) {
1895
0
            memory->free(memory, (URI_CHAR *)uri->portText.first);
1896
0
        }
1897
0
        uri->portText.first = NULL;
1898
0
        uri->portText.afterLast = NULL;
1899
0
    }
1900
1901
    /* Path */
1902
9.43k
    URI_FUNC(FreeUriPath)(uri, memory);
1903
1904
9.43k
    if (uri->owner) {
1905
        /* Query */
1906
0
        if (uri->query.first != NULL) {
1907
0
            if (uri->query.first != uri->query.afterLast) {
1908
0
                memory->free(memory, (URI_CHAR *)uri->query.first);
1909
0
            }
1910
0
            uri->query.first = NULL;
1911
0
            uri->query.afterLast = NULL;
1912
0
        }
1913
1914
        /* Fragment */
1915
0
        if (uri->fragment.first != NULL) {
1916
0
            if (uri->fragment.first != uri->fragment.afterLast) {
1917
0
                memory->free(memory, (URI_CHAR *)uri->fragment.first);
1918
0
            }
1919
0
            uri->fragment.first = NULL;
1920
0
            uri->fragment.afterLast = NULL;
1921
0
        }
1922
0
    }
1923
1924
9.43k
    return URI_SUCCESS;
1925
9.43k
}
Unexecuted instantiation: uriFreeUriMembersMmW
1926
1927
0
UriBool URI_FUNC(_TESTING_ONLY_ParseIpSix)(const URI_CHAR * text) {
1928
0
    UriMemoryManager * const memory = &defaultMemoryManager;
1929
0
    URI_TYPE(Uri) uri;
1930
0
    URI_TYPE(ParserState) parser;
1931
0
    const URI_CHAR * const afterIpSix = text + URI_STRLEN(text);
1932
0
    const URI_CHAR * res;
1933
1934
0
    URI_FUNC(ResetUri)(&uri);
1935
0
    parser.uri = &uri;
1936
0
    URI_FUNC(ResetParserStateExceptUri)(&parser);
1937
0
    parser.uri->hostData.ip6 = memory->malloc(memory, 1 * sizeof(UriIp6));
1938
0
    res = URI_FUNC(ParseIPv6address2)(&parser, text, afterIpSix, memory);
1939
0
    URI_FUNC(FreeUriMembersMm)(&uri, memory);
1940
0
    return res == afterIpSix ? URI_TRUE : URI_FALSE;
1941
0
}
Unexecuted instantiation: uri_TESTING_ONLY_ParseIpSixA
Unexecuted instantiation: uri_TESTING_ONLY_ParseIpSixW
1942
1943
0
UriBool URI_FUNC(_TESTING_ONLY_ParseIpFour)(const URI_CHAR * text) {
1944
0
    unsigned char octets[4];
1945
0
    int res = URI_FUNC(ParseIpFourAddress)(octets, text, text + URI_STRLEN(text));
1946
0
    return (res == URI_SUCCESS) ? URI_TRUE : URI_FALSE;
1947
0
}
Unexecuted instantiation: uri_TESTING_ONLY_ParseIpFourA
Unexecuted instantiation: uri_TESTING_ONLY_ParseIpFourW
1948
1949
#  undef URI_SET_DIGIT
1950
#  undef URI_SET_HEX_LETTER_UPPER
1951
#  undef URI_SET_HEX_LETTER_LOWER
1952
#  undef URI_SET_HEXDIG
1953
#  undef URI_SET_ALPHA
1954
1955
#endif