Coverage Report

Created: 2026-08-13 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/uriparser/src/UriShorten.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
/* What encodings are enabled? */
41
#include <uriparser/UriDefsConfig.h>
42
#if (!defined(URI_PASS_ANSI) && !defined(URI_PASS_UNICODE))
43
/* Include SELF twice */
44
#  ifdef URI_ENABLE_ANSI
45
#    define URI_PASS_ANSI 1
46
#    include "UriShorten.c"
47
#    undef URI_PASS_ANSI
48
#  endif
49
#  ifdef URI_ENABLE_UNICODE
50
#    define URI_PASS_UNICODE 1
51
#    include "UriShorten.c"
52
#    undef URI_PASS_UNICODE
53
#  endif
54
#else
55
#  ifdef URI_PASS_ANSI
56
#    include <uriparser/UriDefsAnsi.h>
57
#  else
58
#    include <uriparser/UriDefsUnicode.h>
59
#    include <wchar.h>
60
#  endif
61
62
#  ifndef URI_DOXYGEN
63
#    include <uriparser/Uri.h>
64
#    include "UriCommon.h"
65
#    include "UriMemory.h"
66
#  endif
67
68
static URI_INLINE UriBool URI_FUNC(AppendSegment)(URI_TYPE(Uri) * uri,
69
874
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
70
    /* Create segment */
71
874
    URI_TYPE(PathSegment) * segment =
72
874
            memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment)));
73
874
    if (segment == NULL) {
74
0
        return URI_FALSE; /* Raises malloc error */
75
0
    }
76
874
    segment->next = NULL;
77
874
    segment->text.first = first;
78
874
    segment->text.afterLast = afterLast;
79
80
    /* Put into chain */
81
874
    if (uri->pathTail == NULL) {
82
57
        uri->pathHead = segment;
83
817
    } else {
84
817
        uri->pathTail->next = segment;
85
817
    }
86
874
    uri->pathTail = segment;
87
88
874
    return URI_TRUE;
89
874
}
Unexecuted instantiation: UriShorten.c:uriAppendSegmentA
UriShorten.c:uriAppendSegmentW
Line
Count
Source
69
874
        const URI_CHAR * first, const URI_CHAR * afterLast, UriMemoryManager * memory) {
70
    /* Create segment */
71
874
    URI_TYPE(PathSegment) * segment =
72
874
            memory->malloc(memory, 1 * sizeof(URI_TYPE(PathSegment)));
73
874
    if (segment == NULL) {
74
0
        return URI_FALSE; /* Raises malloc error */
75
0
    }
76
874
    segment->next = NULL;
77
874
    segment->text.first = first;
78
874
    segment->text.afterLast = afterLast;
79
80
    /* Put into chain */
81
874
    if (uri->pathTail == NULL) {
82
57
        uri->pathHead = segment;
83
817
    } else {
84
817
        uri->pathTail->next = segment;
85
817
    }
86
874
    uri->pathTail = segment;
87
88
874
    return URI_TRUE;
89
874
}
90
91
static URI_INLINE UriBool URI_FUNC(EqualsAuthority)(
92
151
        const URI_TYPE(Uri) * first, const URI_TYPE(Uri) * second) {
93
    /* IPv4 */
94
151
    if (first->hostData.ip4 != NULL) {
95
4
        return ((second->hostData.ip4 != NULL)
96
3
                       && !memcmp(
97
3
                               first->hostData.ip4->data, second->hostData.ip4->data, 4))
98
4
                       ? URI_TRUE
99
4
                       : URI_FALSE;
100
4
    }
101
102
    /* IPv6 */
103
147
    if (first->hostData.ip6 != NULL) {
104
21
        return ((second->hostData.ip6 != NULL)
105
20
                       && !memcmp(
106
20
                               first->hostData.ip6->data, second->hostData.ip6->data, 16))
107
21
                       ? URI_TRUE
108
21
                       : URI_FALSE;
109
21
    }
110
111
    /* IPvFuture */
112
126
    if (first->hostData.ipFuture.first != NULL) {
113
3
        return ((second->hostData.ipFuture.first != NULL)
114
2
                       && URI_FUNC(RangeEquals)(
115
2
                               &first->hostData.ipFuture, &second->hostData.ipFuture))
116
3
                       ? URI_TRUE
117
3
                       : URI_FALSE;
118
3
    }
119
120
123
    return URI_FUNC(RangeEquals)(&first->hostText, &second->hostText) ? URI_TRUE
121
123
                                                                      : URI_FALSE;
122
126
}
Unexecuted instantiation: UriShorten.c:uriEqualsAuthorityA
UriShorten.c:uriEqualsAuthorityW
Line
Count
Source
92
151
        const URI_TYPE(Uri) * first, const URI_TYPE(Uri) * second) {
93
    /* IPv4 */
94
151
    if (first->hostData.ip4 != NULL) {
95
4
        return ((second->hostData.ip4 != NULL)
96
3
                       && !memcmp(
97
3
                               first->hostData.ip4->data, second->hostData.ip4->data, 4))
98
4
                       ? URI_TRUE
99
4
                       : URI_FALSE;
100
4
    }
101
102
    /* IPv6 */
103
147
    if (first->hostData.ip6 != NULL) {
104
21
        return ((second->hostData.ip6 != NULL)
105
20
                       && !memcmp(
106
20
                               first->hostData.ip6->data, second->hostData.ip6->data, 16))
107
21
                       ? URI_TRUE
108
21
                       : URI_FALSE;
109
21
    }
110
111
    /* IPvFuture */
112
126
    if (first->hostData.ipFuture.first != NULL) {
113
3
        return ((second->hostData.ipFuture.first != NULL)
114
2
                       && URI_FUNC(RangeEquals)(
115
2
                               &first->hostData.ipFuture, &second->hostData.ipFuture))
116
3
                       ? URI_TRUE
117
3
                       : URI_FALSE;
118
3
    }
119
120
123
    return URI_FUNC(RangeEquals)(&first->hostText, &second->hostText) ? URI_TRUE
121
123
                                                                      : URI_FALSE;
122
126
}
123
124
static int URI_FUNC(RemoveBaseUriImpl)(URI_TYPE(Uri) * dest,
125
        const URI_TYPE(Uri) * absSource, const URI_TYPE(Uri) * absBase,
126
6.53k
        UriBool domainRootMode, UriMemoryManager * memory) {
127
6.53k
    if (dest == NULL) {
128
0
        return URI_ERROR_NULL;
129
0
    }
130
6.53k
    URI_FUNC(ResetUri)(dest);
131
132
6.53k
    if ((absSource == NULL) || (absBase == NULL)) {
133
0
        return URI_ERROR_NULL;
134
0
    }
135
136
    /* absBase absolute? */
137
6.53k
    if (absBase->scheme.first == NULL) {
138
6.15k
        return URI_ERROR_REMOVEBASE_REL_BASE;
139
6.15k
    }
140
141
    /* absSource absolute? */
142
376
    if (absSource->scheme.first == NULL) {
143
184
        return URI_ERROR_REMOVEBASE_REL_SOURCE;
144
184
    }
145
146
    /* NOTE: The curly brackets here force deeper indent (and that's all) */
147
192
    {
148
192
        {
149
192
            {
150
                /* clang-format off */
151
    /* [01/50] if (A.scheme != Base.scheme) then */
152
                /* clang-format on */
153
192
                if (!URI_FUNC(RangeEquals)(&absSource->scheme, &absBase->scheme)) {
154
                    /* clang-format off */
155
    /* [02/50]    T.scheme    = A.scheme; */
156
                    /* clang-format on */
157
41
                    dest->scheme = absSource->scheme;
158
                    /* clang-format off */
159
    /* [03/50]    T.authority = A.authority; */
160
                    /* clang-format on */
161
41
                    if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
162
0
                        return URI_ERROR_MALLOC;
163
0
                    }
164
                    /* clang-format off */
165
    /* [04/50]    T.path      = A.path; */
166
                    /* clang-format on */
167
41
                    if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
168
0
                        return URI_ERROR_MALLOC;
169
0
                    }
170
                    /* clang-format off */
171
    /* [05/50] else */
172
                    /* clang-format on */
173
151
                } else {
174
                    /* clang-format off */
175
    /* [06/50]    undef(T.scheme); */
176
                    /* clang-format on */
177
                    /* NOOP */
178
                    /* clang-format off */
179
    /* [07/50]    if (A.authority != Base.authority) then */
180
                    /* clang-format on */
181
151
                    if (!URI_FUNC(EqualsAuthority)(absSource, absBase)) {
182
                        /* clang-format off */
183
    /* [08/50]       T.authority = A.authority; */
184
                        /* clang-format on */
185
26
                        if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
186
0
                            return URI_ERROR_MALLOC;
187
0
                        }
188
                        /* clang-format off */
189
    /* [09/50]       T.path      = A.path; */
190
                        /* clang-format on */
191
26
                        if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
192
0
                            return URI_ERROR_MALLOC;
193
0
                        }
194
                        /* clang-format off */
195
    /* [10/50]    else */
196
                        /* clang-format on */
197
125
                    } else {
198
                        /* clang-format off */
199
    /* [11/50]       if domainRootMode then */
200
                        /* clang-format on */
201
125
                        if (domainRootMode == URI_TRUE) {
202
                            /* clang-format off */
203
    /* [12/50]          undef(T.authority); */
204
                            /* clang-format on */
205
                            /* NOOP */
206
                            /* clang-format off */
207
    /* [13/50]          if (first(A.path) == "") then */
208
                            /* clang-format on */
209
                            /* GROUPED */
210
                            /* clang-format off */
211
    /* [14/50]             T.path   = "/." + A.path; */
212
                            /* clang-format on */
213
                            /* GROUPED */
214
                            /* clang-format off */
215
    /* [15/50]          else */
216
                            /* clang-format on */
217
                            /* GROUPED */
218
                            /* clang-format off */
219
    /* [16/50]             T.path   = A.path; */
220
                            /* clang-format on */
221
                            /* GROUPED */
222
                            /* clang-format off */
223
    /* [17/50]          endif; */
224
                            /* clang-format on */
225
24
                            if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
226
0
                                return URI_ERROR_MALLOC;
227
0
                            }
228
24
                            dest->absolutePath = URI_TRUE;
229
230
24
                            if (!URI_FUNC(FixAmbiguity)(dest, memory)) {
231
0
                                return URI_ERROR_MALLOC;
232
0
                            }
233
                            /* clang-format off */
234
    /* [18/50]       else */
235
                            /* clang-format on */
236
101
                        } else {
237
101
                            const URI_TYPE(PathSegment) * sourceSeg = absSource->pathHead;
238
101
                            const URI_TYPE(PathSegment) * baseSeg = absBase->pathHead;
239
                            /* clang-format off */
240
    /* [19/50]          bool pathNaked = true; */
241
                            /* clang-format on */
242
101
                            UriBool pathNaked = URI_TRUE;
243
                            /* clang-format off */
244
    /* [20/50]          undef(last(Base.path)); */
245
                            /* clang-format on */
246
                            /* NOOP */
247
                            /* clang-format off */
248
    /* [21/50]          T.path = ""; */
249
                            /* clang-format on */
250
101
                            dest->absolutePath = URI_FALSE;
251
                            /* clang-format off */
252
    /* [22/50]          while (first(A.path) == first(Base.path)) do */
253
                            /* clang-format on */
254
447
                            while ((sourceSeg != NULL) && (baseSeg != NULL)
255
359
                                    && URI_FUNC(RangeEquals)(
256
359
                                            &sourceSeg->text, &baseSeg->text)
257
349
                                    && !((sourceSeg->text.first
258
349
                                                 == sourceSeg->text.afterLast)
259
108
                                            && ((sourceSeg->next == NULL)
260
346
                                                    != (baseSeg->next == NULL)))) {
261
                                /* clang-format off */
262
    /* [23/50]             A.path++; */
263
                                /* clang-format on */
264
346
                                sourceSeg = sourceSeg->next;
265
                                /* clang-format off */
266
    /* [24/50]             Base.path++; */
267
                                /* clang-format on */
268
346
                                baseSeg = baseSeg->next;
269
                                /* clang-format off */
270
    /* [25/50]          endwhile; */
271
                                /* clang-format on */
272
346
                            }
273
                            /* clang-format off */
274
    /* [26/50]          while defined(first(Base.path)) do */
275
                            /* clang-format on */
276
533
                            while ((baseSeg != NULL) && (baseSeg->next != NULL)) {
277
                                /* clang-format off */
278
    /* [27/50]             Base.path++; */
279
                                /* clang-format on */
280
432
                                baseSeg = baseSeg->next;
281
                                /* clang-format off */
282
    /* [28/50]             T.path += "../"; */
283
                                /* clang-format on */
284
432
                                if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstParent),
285
432
                                            URI_FUNC(ConstParent) + 2, memory)) {
286
0
                                    return URI_ERROR_MALLOC;
287
0
                                }
288
                                /* clang-format off */
289
    /* [29/50]             pathNaked = false; */
290
                                /* clang-format on */
291
432
                                pathNaked = URI_FALSE;
292
                                /* clang-format off */
293
    /* [30/50]          endwhile; */
294
                                /* clang-format on */
295
432
                            }
296
                            /* clang-format off */
297
    /* [31/50]          while defined(first(A.path)) do */
298
                            /* clang-format on */
299
528
                            while (sourceSeg != NULL) {
300
                                /* clang-format off */
301
    /* [32/50]             if pathNaked then */
302
                                /* clang-format on */
303
427
                                if (pathNaked == URI_TRUE) {
304
                                    /* clang-format off */
305
    /* [33/50]                if (first(A.path) contains ":") then */
306
                                    /* clang-format on */
307
39
                                    UriBool containsColon = URI_FALSE;
308
39
                                    const URI_CHAR * ch = sourceSeg->text.first;
309
287
                                    for (; ch < sourceSeg->text.afterLast; ch++) {
310
260
                                        if (*ch == _UT(':')) {
311
12
                                            containsColon = URI_TRUE;
312
12
                                            break;
313
12
                                        }
314
260
                                    }
315
316
39
                                    if (containsColon) {
317
                                        /* clang-format off */
318
    /* [34/50]                   T.path += "./"; */
319
                                        /* clang-format on */
320
12
                                        if (!URI_FUNC(AppendSegment)(dest,
321
12
                                                    URI_FUNC(ConstPwd),
322
12
                                                    URI_FUNC(ConstPwd) + 1, memory)) {
323
0
                                            return URI_ERROR_MALLOC;
324
0
                                        }
325
                                        /* clang-format off */
326
    /* [35/50]                elseif (first(A.path) == "") then */
327
                                        /* clang-format on */
328
27
                                    } else if (sourceSeg->text.first
329
27
                                               == sourceSeg->text.afterLast) {
330
                                        /* clang-format off */
331
    /* [36/50]                   T.path += "/."; */
332
                                        /* clang-format on */
333
3
                                        if (!URI_FUNC(AppendSegment)(dest,
334
3
                                                    URI_FUNC(ConstPwd),
335
3
                                                    URI_FUNC(ConstPwd) + 1, memory)) {
336
0
                                            return URI_ERROR_MALLOC;
337
0
                                        }
338
                                        /* clang-format off */
339
    /* [37/50]                endif; */
340
                                        /* clang-format on */
341
3
                                    }
342
                                    /* clang-format off */
343
    /* [38/50]             endif; */
344
                                    /* clang-format on */
345
39
                                }
346
                                /* clang-format off */
347
    /* [39/50]             T.path += first(A.path); */
348
                                /* clang-format on */
349
427
                                if (!URI_FUNC(AppendSegment)(dest, sourceSeg->text.first,
350
427
                                            sourceSeg->text.afterLast, memory)) {
351
0
                                    return URI_ERROR_MALLOC;
352
0
                                }
353
                                /* clang-format off */
354
    /* [40/50]             pathNaked = false; */
355
                                /* clang-format on */
356
427
                                pathNaked = URI_FALSE;
357
                                /* clang-format off */
358
    /* [41/50]             A.path++; */
359
                                /* clang-format on */
360
427
                                sourceSeg = sourceSeg->next;
361
                                /* clang-format off */
362
    /* [42/50]             if defined(first(A.path)) then */
363
                                /* clang-format on */
364
                                /* NOOP */
365
                                /* clang-format off */
366
    /* [43/50]                T.path += + "/"; */
367
                                /* clang-format on */
368
                                /* NOOP */
369
                                /* clang-format off */
370
    /* [44/50]             endif; */
371
                                /* clang-format on */
372
                                /* NOOP */
373
                                /* clang-format off */
374
    /* [45/50]          endwhile; */
375
                                /* clang-format on */
376
427
                            }
377
                            /* clang-format off */
378
    /* [46/50]       endif; */
379
                            /* clang-format on */
380
101
                        }
381
                        /* clang-format off */
382
    /* [47/50]    endif; */
383
                        /* clang-format on */
384
125
                    }
385
                    /* clang-format off */
386
    /* [48/50] endif; */
387
                    /* clang-format on */
388
151
                }
389
                /* clang-format off */
390
    /* [49/50] T.query     = A.query; */
391
                /* clang-format on */
392
192
                dest->query = absSource->query;
393
                /* clang-format off */
394
    /* [50/50] T.fragment  = A.fragment; */
395
                /* clang-format on */
396
192
                dest->fragment = absSource->fragment;
397
192
            }
398
192
        }
399
192
    }
400
192
    return URI_SUCCESS;
401
192
}
Unexecuted instantiation: UriShorten.c:uriRemoveBaseUriImplA
UriShorten.c:uriRemoveBaseUriImplW
Line
Count
Source
126
6.53k
        UriBool domainRootMode, UriMemoryManager * memory) {
127
6.53k
    if (dest == NULL) {
128
0
        return URI_ERROR_NULL;
129
0
    }
130
6.53k
    URI_FUNC(ResetUri)(dest);
131
132
6.53k
    if ((absSource == NULL) || (absBase == NULL)) {
133
0
        return URI_ERROR_NULL;
134
0
    }
135
136
    /* absBase absolute? */
137
6.53k
    if (absBase->scheme.first == NULL) {
138
6.15k
        return URI_ERROR_REMOVEBASE_REL_BASE;
139
6.15k
    }
140
141
    /* absSource absolute? */
142
376
    if (absSource->scheme.first == NULL) {
143
184
        return URI_ERROR_REMOVEBASE_REL_SOURCE;
144
184
    }
145
146
    /* NOTE: The curly brackets here force deeper indent (and that's all) */
147
192
    {
148
192
        {
149
192
            {
150
                /* clang-format off */
151
    /* [01/50] if (A.scheme != Base.scheme) then */
152
                /* clang-format on */
153
192
                if (!URI_FUNC(RangeEquals)(&absSource->scheme, &absBase->scheme)) {
154
                    /* clang-format off */
155
    /* [02/50]    T.scheme    = A.scheme; */
156
                    /* clang-format on */
157
41
                    dest->scheme = absSource->scheme;
158
                    /* clang-format off */
159
    /* [03/50]    T.authority = A.authority; */
160
                    /* clang-format on */
161
41
                    if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
162
0
                        return URI_ERROR_MALLOC;
163
0
                    }
164
                    /* clang-format off */
165
    /* [04/50]    T.path      = A.path; */
166
                    /* clang-format on */
167
41
                    if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
168
0
                        return URI_ERROR_MALLOC;
169
0
                    }
170
                    /* clang-format off */
171
    /* [05/50] else */
172
                    /* clang-format on */
173
151
                } else {
174
                    /* clang-format off */
175
    /* [06/50]    undef(T.scheme); */
176
                    /* clang-format on */
177
                    /* NOOP */
178
                    /* clang-format off */
179
    /* [07/50]    if (A.authority != Base.authority) then */
180
                    /* clang-format on */
181
151
                    if (!URI_FUNC(EqualsAuthority)(absSource, absBase)) {
182
                        /* clang-format off */
183
    /* [08/50]       T.authority = A.authority; */
184
                        /* clang-format on */
185
26
                        if (!URI_FUNC(CopyAuthority)(dest, absSource, memory)) {
186
0
                            return URI_ERROR_MALLOC;
187
0
                        }
188
                        /* clang-format off */
189
    /* [09/50]       T.path      = A.path; */
190
                        /* clang-format on */
191
26
                        if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
192
0
                            return URI_ERROR_MALLOC;
193
0
                        }
194
                        /* clang-format off */
195
    /* [10/50]    else */
196
                        /* clang-format on */
197
125
                    } else {
198
                        /* clang-format off */
199
    /* [11/50]       if domainRootMode then */
200
                        /* clang-format on */
201
125
                        if (domainRootMode == URI_TRUE) {
202
                            /* clang-format off */
203
    /* [12/50]          undef(T.authority); */
204
                            /* clang-format on */
205
                            /* NOOP */
206
                            /* clang-format off */
207
    /* [13/50]          if (first(A.path) == "") then */
208
                            /* clang-format on */
209
                            /* GROUPED */
210
                            /* clang-format off */
211
    /* [14/50]             T.path   = "/." + A.path; */
212
                            /* clang-format on */
213
                            /* GROUPED */
214
                            /* clang-format off */
215
    /* [15/50]          else */
216
                            /* clang-format on */
217
                            /* GROUPED */
218
                            /* clang-format off */
219
    /* [16/50]             T.path   = A.path; */
220
                            /* clang-format on */
221
                            /* GROUPED */
222
                            /* clang-format off */
223
    /* [17/50]          endif; */
224
                            /* clang-format on */
225
24
                            if (!URI_FUNC(CopyPath)(dest, absSource, memory)) {
226
0
                                return URI_ERROR_MALLOC;
227
0
                            }
228
24
                            dest->absolutePath = URI_TRUE;
229
230
24
                            if (!URI_FUNC(FixAmbiguity)(dest, memory)) {
231
0
                                return URI_ERROR_MALLOC;
232
0
                            }
233
                            /* clang-format off */
234
    /* [18/50]       else */
235
                            /* clang-format on */
236
101
                        } else {
237
101
                            const URI_TYPE(PathSegment) * sourceSeg = absSource->pathHead;
238
101
                            const URI_TYPE(PathSegment) * baseSeg = absBase->pathHead;
239
                            /* clang-format off */
240
    /* [19/50]          bool pathNaked = true; */
241
                            /* clang-format on */
242
101
                            UriBool pathNaked = URI_TRUE;
243
                            /* clang-format off */
244
    /* [20/50]          undef(last(Base.path)); */
245
                            /* clang-format on */
246
                            /* NOOP */
247
                            /* clang-format off */
248
    /* [21/50]          T.path = ""; */
249
                            /* clang-format on */
250
101
                            dest->absolutePath = URI_FALSE;
251
                            /* clang-format off */
252
    /* [22/50]          while (first(A.path) == first(Base.path)) do */
253
                            /* clang-format on */
254
447
                            while ((sourceSeg != NULL) && (baseSeg != NULL)
255
359
                                    && URI_FUNC(RangeEquals)(
256
359
                                            &sourceSeg->text, &baseSeg->text)
257
349
                                    && !((sourceSeg->text.first
258
349
                                                 == sourceSeg->text.afterLast)
259
108
                                            && ((sourceSeg->next == NULL)
260
346
                                                    != (baseSeg->next == NULL)))) {
261
                                /* clang-format off */
262
    /* [23/50]             A.path++; */
263
                                /* clang-format on */
264
346
                                sourceSeg = sourceSeg->next;
265
                                /* clang-format off */
266
    /* [24/50]             Base.path++; */
267
                                /* clang-format on */
268
346
                                baseSeg = baseSeg->next;
269
                                /* clang-format off */
270
    /* [25/50]          endwhile; */
271
                                /* clang-format on */
272
346
                            }
273
                            /* clang-format off */
274
    /* [26/50]          while defined(first(Base.path)) do */
275
                            /* clang-format on */
276
533
                            while ((baseSeg != NULL) && (baseSeg->next != NULL)) {
277
                                /* clang-format off */
278
    /* [27/50]             Base.path++; */
279
                                /* clang-format on */
280
432
                                baseSeg = baseSeg->next;
281
                                /* clang-format off */
282
    /* [28/50]             T.path += "../"; */
283
                                /* clang-format on */
284
432
                                if (!URI_FUNC(AppendSegment)(dest, URI_FUNC(ConstParent),
285
432
                                            URI_FUNC(ConstParent) + 2, memory)) {
286
0
                                    return URI_ERROR_MALLOC;
287
0
                                }
288
                                /* clang-format off */
289
    /* [29/50]             pathNaked = false; */
290
                                /* clang-format on */
291
432
                                pathNaked = URI_FALSE;
292
                                /* clang-format off */
293
    /* [30/50]          endwhile; */
294
                                /* clang-format on */
295
432
                            }
296
                            /* clang-format off */
297
    /* [31/50]          while defined(first(A.path)) do */
298
                            /* clang-format on */
299
528
                            while (sourceSeg != NULL) {
300
                                /* clang-format off */
301
    /* [32/50]             if pathNaked then */
302
                                /* clang-format on */
303
427
                                if (pathNaked == URI_TRUE) {
304
                                    /* clang-format off */
305
    /* [33/50]                if (first(A.path) contains ":") then */
306
                                    /* clang-format on */
307
39
                                    UriBool containsColon = URI_FALSE;
308
39
                                    const URI_CHAR * ch = sourceSeg->text.first;
309
287
                                    for (; ch < sourceSeg->text.afterLast; ch++) {
310
260
                                        if (*ch == _UT(':')) {
311
12
                                            containsColon = URI_TRUE;
312
12
                                            break;
313
12
                                        }
314
260
                                    }
315
316
39
                                    if (containsColon) {
317
                                        /* clang-format off */
318
    /* [34/50]                   T.path += "./"; */
319
                                        /* clang-format on */
320
12
                                        if (!URI_FUNC(AppendSegment)(dest,
321
12
                                                    URI_FUNC(ConstPwd),
322
12
                                                    URI_FUNC(ConstPwd) + 1, memory)) {
323
0
                                            return URI_ERROR_MALLOC;
324
0
                                        }
325
                                        /* clang-format off */
326
    /* [35/50]                elseif (first(A.path) == "") then */
327
                                        /* clang-format on */
328
27
                                    } else if (sourceSeg->text.first
329
27
                                               == sourceSeg->text.afterLast) {
330
                                        /* clang-format off */
331
    /* [36/50]                   T.path += "/."; */
332
                                        /* clang-format on */
333
3
                                        if (!URI_FUNC(AppendSegment)(dest,
334
3
                                                    URI_FUNC(ConstPwd),
335
3
                                                    URI_FUNC(ConstPwd) + 1, memory)) {
336
0
                                            return URI_ERROR_MALLOC;
337
0
                                        }
338
                                        /* clang-format off */
339
    /* [37/50]                endif; */
340
                                        /* clang-format on */
341
3
                                    }
342
                                    /* clang-format off */
343
    /* [38/50]             endif; */
344
                                    /* clang-format on */
345
39
                                }
346
                                /* clang-format off */
347
    /* [39/50]             T.path += first(A.path); */
348
                                /* clang-format on */
349
427
                                if (!URI_FUNC(AppendSegment)(dest, sourceSeg->text.first,
350
427
                                            sourceSeg->text.afterLast, memory)) {
351
0
                                    return URI_ERROR_MALLOC;
352
0
                                }
353
                                /* clang-format off */
354
    /* [40/50]             pathNaked = false; */
355
                                /* clang-format on */
356
427
                                pathNaked = URI_FALSE;
357
                                /* clang-format off */
358
    /* [41/50]             A.path++; */
359
                                /* clang-format on */
360
427
                                sourceSeg = sourceSeg->next;
361
                                /* clang-format off */
362
    /* [42/50]             if defined(first(A.path)) then */
363
                                /* clang-format on */
364
                                /* NOOP */
365
                                /* clang-format off */
366
    /* [43/50]                T.path += + "/"; */
367
                                /* clang-format on */
368
                                /* NOOP */
369
                                /* clang-format off */
370
    /* [44/50]             endif; */
371
                                /* clang-format on */
372
                                /* NOOP */
373
                                /* clang-format off */
374
    /* [45/50]          endwhile; */
375
                                /* clang-format on */
376
427
                            }
377
                            /* clang-format off */
378
    /* [46/50]       endif; */
379
                            /* clang-format on */
380
101
                        }
381
                        /* clang-format off */
382
    /* [47/50]    endif; */
383
                        /* clang-format on */
384
125
                    }
385
                    /* clang-format off */
386
    /* [48/50] endif; */
387
                    /* clang-format on */
388
151
                }
389
                /* clang-format off */
390
    /* [49/50] T.query     = A.query; */
391
                /* clang-format on */
392
192
                dest->query = absSource->query;
393
                /* clang-format off */
394
    /* [50/50] T.fragment  = A.fragment; */
395
                /* clang-format on */
396
192
                dest->fragment = absSource->fragment;
397
192
            }
398
192
        }
399
192
    }
400
192
    return URI_SUCCESS;
401
192
}
402
403
int URI_FUNC(RemoveBaseUri)(URI_TYPE(Uri) * dest, const URI_TYPE(Uri) * absSource,
404
6.53k
        const URI_TYPE(Uri) * absBase, UriBool domainRootMode) {
405
6.53k
    return URI_FUNC(RemoveBaseUriMm)(dest, absSource, absBase, domainRootMode, NULL);
406
6.53k
}
Unexecuted instantiation: uriRemoveBaseUriA
uriRemoveBaseUriW
Line
Count
Source
404
6.53k
        const URI_TYPE(Uri) * absBase, UriBool domainRootMode) {
405
6.53k
    return URI_FUNC(RemoveBaseUriMm)(dest, absSource, absBase, domainRootMode, NULL);
406
6.53k
}
407
408
int URI_FUNC(RemoveBaseUriMm)(URI_TYPE(Uri) * dest, const URI_TYPE(Uri) * absSource,
409
        const URI_TYPE(Uri) * absBase, UriBool domainRootMode,
410
6.53k
        UriMemoryManager * memory) {
411
6.53k
    int res;
412
413
6.53k
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
414
415
6.53k
    res = URI_FUNC(RemoveBaseUriImpl)(dest, absSource, absBase, domainRootMode, memory);
416
6.53k
    if ((res != URI_SUCCESS) && (dest != NULL)) {
417
6.34k
        URI_FUNC(FreeUriMembersMm)(dest, memory);
418
6.34k
    }
419
6.53k
    return res;
420
6.53k
}
Unexecuted instantiation: uriRemoveBaseUriMmA
uriRemoveBaseUriMmW
Line
Count
Source
410
6.53k
        UriMemoryManager * memory) {
411
6.53k
    int res;
412
413
6.53k
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
414
415
6.53k
    res = URI_FUNC(RemoveBaseUriImpl)(dest, absSource, absBase, domainRootMode, memory);
416
6.53k
    if ((res != URI_SUCCESS) && (dest != NULL)) {
417
6.34k
        URI_FUNC(FreeUriMembersMm)(dest, memory);
418
6.34k
    }
419
6.53k
    return res;
420
6.53k
}
421
422
#endif