Coverage Report

Created: 2026-07-16 06:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/uriparser/src/UriNormalize.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 UriNormalize.c
42
 * Holds the RFC 3986 %URI normalization 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 "UriNormalize.c"
53
#    undef URI_PASS_ANSI
54
#  endif
55
#  ifdef URI_ENABLE_UNICODE
56
#    define URI_PASS_UNICODE 1
57
#    include "UriNormalize.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 "UriNormalizeBase.h"
71
#    include "UriCommon.h"
72
#    include "UriMemory.h"
73
#  endif
74
75
#  include <assert.h>
76
#  include <stdint.h>  // SIZE_MAX
77
78
static int URI_FUNC(NormalizeSyntaxEngine)(URI_TYPE(Uri) * uri, unsigned int inMask,
79
        unsigned int * outMask, UriMemoryManager * memory);
80
81
static UriBool URI_FUNC(MakeRangeOwner)(unsigned int * revertMask, unsigned int maskTest,
82
        URI_TYPE(TextRange) * range, UriMemoryManager * memory);
83
static UriBool URI_FUNC(MakeOwnerEngine)(
84
        URI_TYPE(Uri) * uri, unsigned int * revertMask, UriMemoryManager * memory);
85
86
static void URI_FUNC(FixPercentEncodingInplace)(
87
        const URI_CHAR * first, const URI_CHAR ** afterLast);
88
static UriBool URI_FUNC(FixPercentEncodingMalloc)(
89
        const URI_CHAR ** first, const URI_CHAR ** afterLast, UriMemoryManager * memory);
90
static void URI_FUNC(FixPercentEncodingEngine)(const URI_CHAR * inFirst,
91
        const URI_CHAR * inAfterLast, const URI_CHAR * outFirst,
92
        const URI_CHAR ** outAfterLast);
93
94
static UriBool URI_FUNC(ContainsUppercaseLetters)(
95
        const URI_CHAR * first, const URI_CHAR * afterLast);
96
static UriBool URI_FUNC(ContainsUglyPercentEncoding)(
97
        const URI_CHAR * first, const URI_CHAR * afterLast);
98
99
static void URI_FUNC(LowercaseInplace)(
100
        const URI_CHAR * first, const URI_CHAR * afterLast);
101
static void URI_FUNC(LowercaseInplaceExceptPercentEncoding)(
102
        const URI_CHAR * first, const URI_CHAR * afterLast);
103
static UriBool URI_FUNC(LowercaseMalloc)(
104
        const URI_CHAR ** first, const URI_CHAR ** afterLast, UriMemoryManager * memory);
105
106
void URI_FUNC(PreventLeakage)(
107
0
        URI_TYPE(Uri) * uri, unsigned int revertMask, UriMemoryManager * memory) {
108
0
    if (revertMask & URI_NORMALIZE_SCHEME) {
109
        /* NOTE: A scheme cannot be the empty string
110
         *       so no need to compare .first with .afterLast, here. */
111
0
        memory->free(memory, (URI_CHAR *)uri->scheme.first);
112
0
        uri->scheme.first = NULL;
113
0
        uri->scheme.afterLast = NULL;
114
0
    }
115
116
0
    if (revertMask & URI_NORMALIZE_USER_INFO) {
117
0
        if (uri->userInfo.first != uri->userInfo.afterLast) {
118
0
            memory->free(memory, (URI_CHAR *)uri->userInfo.first);
119
0
        }
120
0
        uri->userInfo.first = NULL;
121
0
        uri->userInfo.afterLast = NULL;
122
0
    }
123
124
0
    if (revertMask & URI_NORMALIZE_HOST) {
125
0
        if (uri->hostData.ipFuture.first != NULL) {
126
            /* IPvFuture */
127
            /* NOTE: An IPvFuture address cannot be the empty string
128
             *       so no need to compare .first with .afterLast, here. */
129
0
            memory->free(memory, (URI_CHAR *)uri->hostData.ipFuture.first);
130
0
            uri->hostData.ipFuture.first = NULL;
131
0
            uri->hostData.ipFuture.afterLast = NULL;
132
0
            uri->hostText.first = NULL;
133
0
            uri->hostText.afterLast = NULL;
134
0
        } else if (uri->hostText.first != NULL) {
135
            /* Regname */
136
0
            if (uri->hostText.first != uri->hostText.afterLast) {
137
0
                memory->free(memory, (URI_CHAR *)uri->hostText.first);
138
0
            }
139
0
            uri->hostText.first = NULL;
140
0
            uri->hostText.afterLast = NULL;
141
0
        }
142
0
    }
143
144
    /* NOTE: Port cannot happen! */
145
146
0
    if (revertMask & URI_NORMALIZE_PATH) {
147
0
        URI_TYPE(PathSegment) * walker = uri->pathHead;
148
0
        while (walker != NULL) {
149
0
            URI_TYPE(PathSegment) * const next = walker->next;
150
0
            if (walker->text.afterLast > walker->text.first) {
151
0
                memory->free(memory, (URI_CHAR *)walker->text.first);
152
0
            }
153
0
            memory->free(memory, walker);
154
0
            walker = next;
155
0
        }
156
0
        uri->pathHead = NULL;
157
0
        uri->pathTail = NULL;
158
0
    }
159
160
0
    if (revertMask & URI_NORMALIZE_QUERY) {
161
0
        if (uri->query.first != uri->query.afterLast) {
162
0
            memory->free(memory, (URI_CHAR *)uri->query.first);
163
0
        }
164
0
        uri->query.first = NULL;
165
0
        uri->query.afterLast = NULL;
166
0
    }
167
168
0
    if (revertMask & URI_NORMALIZE_FRAGMENT) {
169
0
        if (uri->fragment.first != uri->fragment.afterLast) {
170
0
            memory->free(memory, (URI_CHAR *)uri->fragment.first);
171
0
        }
172
0
        uri->fragment.first = NULL;
173
0
        uri->fragment.afterLast = NULL;
174
0
    }
175
0
}
Unexecuted instantiation: uriPreventLeakageA
Unexecuted instantiation: uriPreventLeakageW
176
177
static URI_INLINE UriBool URI_FUNC(ContainsUppercaseLetters)(
178
13.5k
        const URI_CHAR * first, const URI_CHAR * afterLast) {
179
13.5k
    if ((first != NULL) && (afterLast != NULL) && (afterLast > first)) {
180
1.59k
        const URI_CHAR * i = first;
181
261k
        for (; i < afterLast; i++) {
182
            /* 6.2.2.1 Case Normalization: uppercase letters in scheme or host */
183
260k
            if ((*i >= _UT('A')) && (*i <= _UT('Z'))) {
184
631
                return URI_TRUE;
185
631
            }
186
260k
        }
187
1.59k
    }
188
12.9k
    return URI_FALSE;
189
13.5k
}
UriNormalize.c:uriContainsUppercaseLettersA
Line
Count
Source
178
13.5k
        const URI_CHAR * first, const URI_CHAR * afterLast) {
179
13.5k
    if ((first != NULL) && (afterLast != NULL) && (afterLast > first)) {
180
1.59k
        const URI_CHAR * i = first;
181
261k
        for (; i < afterLast; i++) {
182
            /* 6.2.2.1 Case Normalization: uppercase letters in scheme or host */
183
260k
            if ((*i >= _UT('A')) && (*i <= _UT('Z'))) {
184
631
                return URI_TRUE;
185
631
            }
186
260k
        }
187
1.59k
    }
188
12.9k
    return URI_FALSE;
189
13.5k
}
Unexecuted instantiation: UriNormalize.c:uriContainsUppercaseLettersW
190
191
static URI_INLINE UriBool URI_FUNC(ContainsUglyPercentEncoding)(
192
31.6k
        const URI_CHAR * first, const URI_CHAR * afterLast) {
193
31.6k
    if ((first != NULL) && (afterLast != NULL) && (afterLast > first)) {
194
6.07k
        const URI_CHAR * i = first;
195
10.0M
        for (; i + 2 < afterLast; i++) {
196
10.0M
            if (i[0] == _UT('%')) {
197
                /* 6.2.2.1 Case Normalization: *
198
                 * lowercase percent-encodings */
199
2.88k
                if (((i[1] >= _UT('a')) && (i[1] <= _UT('f')))
200
2.80k
                        || ((i[2] >= _UT('a')) && (i[2] <= _UT('f')))) {
201
141
                    return URI_TRUE;
202
2.74k
                } else {
203
                    /* 6.2.2.2 Percent-Encoding Normalization: *
204
                     * percent-encoded unreserved characters   */
205
2.74k
                    const unsigned char left = URI_FUNC(HexdigToInt)(i[1]);
206
2.74k
                    const unsigned char right = URI_FUNC(HexdigToInt)(i[2]);
207
2.74k
                    const int code = 16 * left + right;
208
2.74k
                    if (uriIsUnreserved(code)) {
209
146
                        return URI_TRUE;
210
146
                    }
211
2.74k
                }
212
2.88k
            }
213
10.0M
        }
214
6.07k
    }
215
31.3k
    return URI_FALSE;
216
31.6k
}
UriNormalize.c:uriContainsUglyPercentEncodingA
Line
Count
Source
192
31.6k
        const URI_CHAR * first, const URI_CHAR * afterLast) {
193
31.6k
    if ((first != NULL) && (afterLast != NULL) && (afterLast > first)) {
194
6.07k
        const URI_CHAR * i = first;
195
10.0M
        for (; i + 2 < afterLast; i++) {
196
10.0M
            if (i[0] == _UT('%')) {
197
                /* 6.2.2.1 Case Normalization: *
198
                 * lowercase percent-encodings */
199
2.88k
                if (((i[1] >= _UT('a')) && (i[1] <= _UT('f')))
200
2.80k
                        || ((i[2] >= _UT('a')) && (i[2] <= _UT('f')))) {
201
141
                    return URI_TRUE;
202
2.74k
                } else {
203
                    /* 6.2.2.2 Percent-Encoding Normalization: *
204
                     * percent-encoded unreserved characters   */
205
2.74k
                    const unsigned char left = URI_FUNC(HexdigToInt)(i[1]);
206
2.74k
                    const unsigned char right = URI_FUNC(HexdigToInt)(i[2]);
207
2.74k
                    const int code = 16 * left + right;
208
2.74k
                    if (uriIsUnreserved(code)) {
209
146
                        return URI_TRUE;
210
146
                    }
211
2.74k
                }
212
2.88k
            }
213
10.0M
        }
214
6.07k
    }
215
31.3k
    return URI_FALSE;
216
31.6k
}
Unexecuted instantiation: UriNormalize.c:uriContainsUglyPercentEncodingW
217
218
static URI_INLINE void URI_FUNC(LowercaseInplace)(
219
0
        const URI_CHAR * first, const URI_CHAR * afterLast) {
220
0
    if ((first != NULL) && (afterLast != NULL) && (afterLast > first)) {
221
0
        URI_CHAR * i = (URI_CHAR *)first;
222
0
        const int lowerUpperDiff = (_UT('a') - _UT('A'));
223
0
        for (; i < afterLast; i++) {
224
0
            if ((*i >= _UT('A')) && (*i <= _UT('Z'))) {
225
0
                *i = (URI_CHAR)(*i + lowerUpperDiff);
226
0
            }
227
0
        }
228
0
    }
229
0
}
Unexecuted instantiation: UriNormalize.c:uriLowercaseInplaceA
Unexecuted instantiation: UriNormalize.c:uriLowercaseInplaceW
230
231
static URI_INLINE void URI_FUNC(LowercaseInplaceExceptPercentEncoding)(
232
1.06k
        const URI_CHAR * first, const URI_CHAR * afterLast) {
233
1.06k
    if ((first != NULL) && (afterLast != NULL) && (afterLast > first)) {
234
900
        URI_CHAR * i = (URI_CHAR *)first;
235
900
        const int lowerUpperDiff = (_UT('a') - _UT('A'));
236
2.07M
        for (; i < afterLast; i++) {
237
2.06M
            if ((*i >= _UT('A')) && (*i <= _UT('Z'))) {
238
1.13M
                *i = (URI_CHAR)(*i + lowerUpperDiff);
239
1.13M
            } else if (*i == _UT('%')) {
240
1.54k
                if (i + 3 >= afterLast) {
241
9
                    return;
242
9
                }
243
1.53k
                i += 2;
244
1.53k
            }
245
2.06M
        }
246
900
    }
247
1.06k
}
UriNormalize.c:uriLowercaseInplaceExceptPercentEncodingA
Line
Count
Source
232
1.06k
        const URI_CHAR * first, const URI_CHAR * afterLast) {
233
1.06k
    if ((first != NULL) && (afterLast != NULL) && (afterLast > first)) {
234
900
        URI_CHAR * i = (URI_CHAR *)first;
235
900
        const int lowerUpperDiff = (_UT('a') - _UT('A'));
236
2.07M
        for (; i < afterLast; i++) {
237
2.06M
            if ((*i >= _UT('A')) && (*i <= _UT('Z'))) {
238
1.13M
                *i = (URI_CHAR)(*i + lowerUpperDiff);
239
1.13M
            } else if (*i == _UT('%')) {
240
1.54k
                if (i + 3 >= afterLast) {
241
9
                    return;
242
9
                }
243
1.53k
                i += 2;
244
1.53k
            }
245
2.06M
        }
246
900
    }
247
1.06k
}
Unexecuted instantiation: UriNormalize.c:uriLowercaseInplaceExceptPercentEncodingW
248
249
static URI_INLINE UriBool URI_FUNC(LowercaseMalloc)(
250
645
        const URI_CHAR ** first, const URI_CHAR ** afterLast, UriMemoryManager * memory) {
251
645
    const int lowerUpperDiff = (_UT('a') - _UT('A'));
252
645
    URI_CHAR * buffer;
253
645
    size_t i = 0;
254
255
645
    if ((first == NULL) || (afterLast == NULL) || (*first == NULL)
256
645
            || (*afterLast == NULL)) {
257
0
        return URI_FALSE;
258
0
    }
259
260
645
    const size_t lenInChars = *afterLast - *first;
261
645
    if (lenInChars == 0) {
262
0
        return URI_TRUE;
263
0
    }
264
265
    // Detect and avoid integer overflow
266
645
    if (lenInChars > SIZE_MAX / sizeof(URI_CHAR)) {
267
0
        return URI_FALSE;
268
0
    }
269
270
645
    buffer = memory->malloc(memory, lenInChars * sizeof(URI_CHAR));
271
645
    if (buffer == NULL) {
272
0
        return URI_FALSE;
273
0
    }
274
275
6.12M
    for (; i < lenInChars; i++) {
276
6.12M
        if (((*first)[i] >= _UT('A')) && ((*first)[i] <= _UT('Z'))) {
277
982k
            buffer[i] = (URI_CHAR)((*first)[i] + lowerUpperDiff);
278
5.14M
        } else {
279
5.14M
            buffer[i] = (*first)[i];
280
5.14M
        }
281
6.12M
    }
282
283
645
    *first = buffer;
284
645
    *afterLast = buffer + lenInChars;
285
645
    return URI_TRUE;
286
645
}
UriNormalize.c:uriLowercaseMallocA
Line
Count
Source
250
645
        const URI_CHAR ** first, const URI_CHAR ** afterLast, UriMemoryManager * memory) {
251
645
    const int lowerUpperDiff = (_UT('a') - _UT('A'));
252
645
    URI_CHAR * buffer;
253
645
    size_t i = 0;
254
255
645
    if ((first == NULL) || (afterLast == NULL) || (*first == NULL)
256
645
            || (*afterLast == NULL)) {
257
0
        return URI_FALSE;
258
0
    }
259
260
645
    const size_t lenInChars = *afterLast - *first;
261
645
    if (lenInChars == 0) {
262
0
        return URI_TRUE;
263
0
    }
264
265
    // Detect and avoid integer overflow
266
645
    if (lenInChars > SIZE_MAX / sizeof(URI_CHAR)) {
267
0
        return URI_FALSE;
268
0
    }
269
270
645
    buffer = memory->malloc(memory, lenInChars * sizeof(URI_CHAR));
271
645
    if (buffer == NULL) {
272
0
        return URI_FALSE;
273
0
    }
274
275
6.12M
    for (; i < lenInChars; i++) {
276
6.12M
        if (((*first)[i] >= _UT('A')) && ((*first)[i] <= _UT('Z'))) {
277
982k
            buffer[i] = (URI_CHAR)((*first)[i] + lowerUpperDiff);
278
5.14M
        } else {
279
5.14M
            buffer[i] = (*first)[i];
280
5.14M
        }
281
6.12M
    }
282
283
645
    *first = buffer;
284
645
    *afterLast = buffer + lenInChars;
285
645
    return URI_TRUE;
286
645
}
Unexecuted instantiation: UriNormalize.c:uriLowercaseMallocW
287
288
/* NOTE: Implementation must stay inplace-compatible */
289
static URI_INLINE void URI_FUNC(FixPercentEncodingEngine)(const URI_CHAR * inFirst,
290
        const URI_CHAR * inAfterLast, const URI_CHAR * outFirst,
291
15.9k
        const URI_CHAR ** outAfterLast) {
292
15.9k
    URI_CHAR * write = (URI_CHAR *)outFirst;
293
15.9k
    const size_t lenInChars = inAfterLast - inFirst;
294
15.9k
    size_t i = 0;
295
296
    /* All but last two */
297
14.8M
    for (; i + 2 < lenInChars; i++) {
298
14.8M
        if (inFirst[i] != _UT('%')) {
299
14.7M
            write[0] = inFirst[i];
300
14.7M
            write++;
301
14.7M
        } else {
302
            /* 6.2.2.2 Percent-Encoding Normalization: *
303
             * percent-encoded unreserved characters   */
304
20.7k
            const URI_CHAR one = inFirst[i + 1];
305
20.7k
            const URI_CHAR two = inFirst[i + 2];
306
20.7k
            const unsigned char left = URI_FUNC(HexdigToInt)(one);
307
20.7k
            const unsigned char right = URI_FUNC(HexdigToInt)(two);
308
20.7k
            const int code = 16 * left + right;
309
20.7k
            if (uriIsUnreserved(code)) {
310
12.4k
                write[0] = (URI_CHAR)(code);
311
12.4k
                write++;
312
12.4k
            } else {
313
                /* 6.2.2.1 Case Normalization: *
314
                 * uppercase percent-encodings */
315
8.27k
                write[0] = _UT('%');
316
8.27k
                write[1] = URI_FUNC(HexToLetterEx)(left, URI_TRUE);
317
8.27k
                write[2] = URI_FUNC(HexToLetterEx)(right, URI_TRUE);
318
8.27k
                write += 3;
319
8.27k
            }
320
321
20.7k
            i += 2; /* For the two chars of the percent group we just ate */
322
20.7k
        }
323
14.8M
    }
324
325
    /* Last two */
326
42.0k
    for (; i < lenInChars; i++) {
327
26.0k
        write[0] = inFirst[i];
328
26.0k
        write++;
329
26.0k
    }
330
331
15.9k
    *outAfterLast = write;
332
15.9k
}
UriNormalize.c:uriFixPercentEncodingEngineA
Line
Count
Source
291
15.9k
        const URI_CHAR ** outAfterLast) {
292
15.9k
    URI_CHAR * write = (URI_CHAR *)outFirst;
293
15.9k
    const size_t lenInChars = inAfterLast - inFirst;
294
15.9k
    size_t i = 0;
295
296
    /* All but last two */
297
14.8M
    for (; i + 2 < lenInChars; i++) {
298
14.8M
        if (inFirst[i] != _UT('%')) {
299
14.7M
            write[0] = inFirst[i];
300
14.7M
            write++;
301
14.7M
        } else {
302
            /* 6.2.2.2 Percent-Encoding Normalization: *
303
             * percent-encoded unreserved characters   */
304
20.7k
            const URI_CHAR one = inFirst[i + 1];
305
20.7k
            const URI_CHAR two = inFirst[i + 2];
306
20.7k
            const unsigned char left = URI_FUNC(HexdigToInt)(one);
307
20.7k
            const unsigned char right = URI_FUNC(HexdigToInt)(two);
308
20.7k
            const int code = 16 * left + right;
309
20.7k
            if (uriIsUnreserved(code)) {
310
12.4k
                write[0] = (URI_CHAR)(code);
311
12.4k
                write++;
312
12.4k
            } else {
313
                /* 6.2.2.1 Case Normalization: *
314
                 * uppercase percent-encodings */
315
8.27k
                write[0] = _UT('%');
316
8.27k
                write[1] = URI_FUNC(HexToLetterEx)(left, URI_TRUE);
317
8.27k
                write[2] = URI_FUNC(HexToLetterEx)(right, URI_TRUE);
318
8.27k
                write += 3;
319
8.27k
            }
320
321
20.7k
            i += 2; /* For the two chars of the percent group we just ate */
322
20.7k
        }
323
14.8M
    }
324
325
    /* Last two */
326
42.0k
    for (; i < lenInChars; i++) {
327
26.0k
        write[0] = inFirst[i];
328
26.0k
        write++;
329
26.0k
    }
330
331
15.9k
    *outAfterLast = write;
332
15.9k
}
Unexecuted instantiation: UriNormalize.c:uriFixPercentEncodingEngineW
333
334
static URI_INLINE void URI_FUNC(FixPercentEncodingInplace)(
335
0
        const URI_CHAR * first, const URI_CHAR ** afterLast) {
336
    /* Death checks */
337
0
    if ((first == NULL) || (afterLast == NULL) || (*afterLast == NULL)) {
338
0
        return;
339
0
    }
340
341
    /* Fix inplace */
342
0
    URI_FUNC(FixPercentEncodingEngine)(first, *afterLast, first, afterLast);
343
0
}
Unexecuted instantiation: UriNormalize.c:uriFixPercentEncodingInplaceA
Unexecuted instantiation: UriNormalize.c:uriFixPercentEncodingInplaceW
344
345
static URI_INLINE UriBool URI_FUNC(FixPercentEncodingMalloc)(
346
22.2k
        const URI_CHAR ** first, const URI_CHAR ** afterLast, UriMemoryManager * memory) {
347
22.2k
    URI_CHAR * buffer;
348
349
    /* Death checks */
350
22.2k
    if ((first == NULL) || (afterLast == NULL) || (*first == NULL)
351
22.2k
            || (*afterLast == NULL)) {
352
0
        return URI_FALSE;
353
0
    }
354
355
    /* Old text length */
356
22.2k
    const size_t lenInChars = *afterLast - *first;
357
22.2k
    if (lenInChars == 0) {
358
6.30k
        return URI_TRUE;
359
6.30k
    }
360
361
    // Detect and avoid integer overflow
362
15.9k
    if (lenInChars > SIZE_MAX / sizeof(URI_CHAR)) {
363
0
        return URI_FALSE;
364
0
    }
365
366
    /* New buffer */
367
15.9k
    buffer = memory->malloc(memory, lenInChars * sizeof(URI_CHAR));
368
15.9k
    if (buffer == NULL) {
369
0
        return URI_FALSE;
370
0
    }
371
372
    /* Fix on copy */
373
15.9k
    URI_FUNC(FixPercentEncodingEngine)(*first, *afterLast, buffer, afterLast);
374
15.9k
    *first = buffer;
375
15.9k
    return URI_TRUE;
376
15.9k
}
UriNormalize.c:uriFixPercentEncodingMallocA
Line
Count
Source
346
22.2k
        const URI_CHAR ** first, const URI_CHAR ** afterLast, UriMemoryManager * memory) {
347
22.2k
    URI_CHAR * buffer;
348
349
    /* Death checks */
350
22.2k
    if ((first == NULL) || (afterLast == NULL) || (*first == NULL)
351
22.2k
            || (*afterLast == NULL)) {
352
0
        return URI_FALSE;
353
0
    }
354
355
    /* Old text length */
356
22.2k
    const size_t lenInChars = *afterLast - *first;
357
22.2k
    if (lenInChars == 0) {
358
6.30k
        return URI_TRUE;
359
6.30k
    }
360
361
    // Detect and avoid integer overflow
362
15.9k
    if (lenInChars > SIZE_MAX / sizeof(URI_CHAR)) {
363
0
        return URI_FALSE;
364
0
    }
365
366
    /* New buffer */
367
15.9k
    buffer = memory->malloc(memory, lenInChars * sizeof(URI_CHAR));
368
15.9k
    if (buffer == NULL) {
369
0
        return URI_FALSE;
370
0
    }
371
372
    /* Fix on copy */
373
15.9k
    URI_FUNC(FixPercentEncodingEngine)(*first, *afterLast, buffer, afterLast);
374
15.9k
    *first = buffer;
375
15.9k
    return URI_TRUE;
376
15.9k
}
Unexecuted instantiation: UriNormalize.c:uriFixPercentEncodingMallocW
377
378
static URI_INLINE UriBool URI_FUNC(MakeRangeOwner)(unsigned int * revertMask,
379
34.0k
        unsigned int maskTest, URI_TYPE(TextRange) * range, UriMemoryManager * memory) {
380
34.0k
    if (((*revertMask & maskTest) == 0) && (range->first != NULL)
381
235
            && (range->afterLast != NULL) && (range->afterLast > range->first)) {
382
188
        if (URI_FUNC(CopyRange)(range, range, memory) == URI_FALSE) {
383
0
            return URI_FALSE;
384
0
        }
385
188
        *revertMask |= maskTest;
386
188
    }
387
34.0k
    return URI_TRUE;
388
34.0k
}
UriNormalize.c:uriMakeRangeOwnerA
Line
Count
Source
379
34.0k
        unsigned int maskTest, URI_TYPE(TextRange) * range, UriMemoryManager * memory) {
380
34.0k
    if (((*revertMask & maskTest) == 0) && (range->first != NULL)
381
235
            && (range->afterLast != NULL) && (range->afterLast > range->first)) {
382
188
        if (URI_FUNC(CopyRange)(range, range, memory) == URI_FALSE) {
383
0
            return URI_FALSE;
384
0
        }
385
188
        *revertMask |= maskTest;
386
188
    }
387
34.0k
    return URI_TRUE;
388
34.0k
}
Unexecuted instantiation: UriNormalize.c:uriMakeRangeOwnerW
389
390
static URI_INLINE UriBool URI_FUNC(MakeOwnerEngine)(
391
6.79k
        URI_TYPE(Uri) * uri, unsigned int * revertMask, UriMemoryManager * memory) {
392
6.79k
    URI_TYPE(PathSegment) * walker = uri->pathHead;
393
6.79k
    if (!URI_FUNC(MakeRangeOwner)(
394
6.79k
                revertMask, URI_NORMALIZE_SCHEME, &(uri->scheme), memory)
395
6.79k
            || !URI_FUNC(MakeRangeOwner)(
396
6.79k
                    revertMask, URI_NORMALIZE_USER_INFO, &(uri->userInfo), memory)
397
6.79k
            || !URI_FUNC(MakeRangeOwner)(
398
6.79k
                    revertMask, URI_NORMALIZE_QUERY, &(uri->query), memory)
399
6.79k
            || !URI_FUNC(MakeRangeOwner)(
400
6.79k
                    revertMask, URI_NORMALIZE_FRAGMENT, &(uri->fragment), memory)) {
401
0
        return URI_FALSE; /* Raises malloc error */
402
0
    }
403
404
    /* Host */
405
6.79k
    if ((*revertMask & URI_NORMALIZE_HOST) == 0) {
406
5.60k
        if (uri->hostData.ipFuture.first != NULL) {
407
            /* IPvFuture */
408
0
            if (!URI_FUNC(MakeRangeOwner)(revertMask, URI_NORMALIZE_HOST,
409
0
                        &(uri->hostData.ipFuture), memory)) {
410
0
                return URI_FALSE; /* Raises malloc error */
411
0
            }
412
0
            uri->hostText.first = uri->hostData.ipFuture.first;
413
0
            uri->hostText.afterLast = uri->hostData.ipFuture.afterLast;
414
5.60k
        } else if (uri->hostText.first != NULL) {
415
            /* Regname */
416
53
            if (!URI_FUNC(MakeRangeOwner)(
417
53
                        revertMask, URI_NORMALIZE_HOST, &(uri->hostText), memory)) {
418
0
                return URI_FALSE; /* Raises malloc error */
419
0
            }
420
53
        }
421
5.60k
    }
422
423
    /* Path */
424
6.79k
    if ((*revertMask & URI_NORMALIZE_PATH) == 0) {
425
0
        while (walker != NULL) {
426
0
            if (!URI_FUNC(MakeRangeOwner)(revertMask, 0, &(walker->text), memory)) {
427
                /* Free allocations done so far and kill path */
428
429
                /* Kill path to one before walker (if any) */
430
0
                URI_TYPE(PathSegment) * ranger = uri->pathHead;
431
0
                while (ranger != walker) {
432
0
                    URI_TYPE(PathSegment) * const next = ranger->next;
433
0
                    if ((ranger->text.first != NULL) && (ranger->text.afterLast != NULL)
434
0
                            && (ranger->text.afterLast > ranger->text.first)) {
435
0
                        memory->free(memory, (URI_CHAR *)ranger->text.first);
436
0
                    }
437
0
                    memory->free(memory, ranger);
438
0
                    ranger = next;
439
0
                }
440
441
                /* Kill path from walker */
442
0
                while (walker != NULL) {
443
0
                    URI_TYPE(PathSegment) * const next = walker->next;
444
0
                    memory->free(memory, walker);
445
0
                    walker = next;
446
0
                }
447
448
0
                uri->pathHead = NULL;
449
0
                uri->pathTail = NULL;
450
0
                return URI_FALSE; /* Raises malloc error */
451
0
            }
452
0
            walker = walker->next;
453
0
        }
454
0
        *revertMask |= URI_NORMALIZE_PATH;
455
0
    }
456
457
    /* Port text, must come last so we don't have to undo that one if it fails. *
458
     * Otherwise we would need and extra enum flag for it although the port      *
459
     * cannot go unnormalized...                                                */
460
6.79k
    if (!URI_FUNC(MakeRangeOwner)(revertMask, 0, &(uri->portText), memory)) {
461
0
        return URI_FALSE; /* Raises malloc error */
462
0
    }
463
464
6.79k
    return URI_TRUE;
465
6.79k
}
UriNormalize.c:uriMakeOwnerEngineA
Line
Count
Source
391
6.79k
        URI_TYPE(Uri) * uri, unsigned int * revertMask, UriMemoryManager * memory) {
392
6.79k
    URI_TYPE(PathSegment) * walker = uri->pathHead;
393
6.79k
    if (!URI_FUNC(MakeRangeOwner)(
394
6.79k
                revertMask, URI_NORMALIZE_SCHEME, &(uri->scheme), memory)
395
6.79k
            || !URI_FUNC(MakeRangeOwner)(
396
6.79k
                    revertMask, URI_NORMALIZE_USER_INFO, &(uri->userInfo), memory)
397
6.79k
            || !URI_FUNC(MakeRangeOwner)(
398
6.79k
                    revertMask, URI_NORMALIZE_QUERY, &(uri->query), memory)
399
6.79k
            || !URI_FUNC(MakeRangeOwner)(
400
6.79k
                    revertMask, URI_NORMALIZE_FRAGMENT, &(uri->fragment), memory)) {
401
0
        return URI_FALSE; /* Raises malloc error */
402
0
    }
403
404
    /* Host */
405
6.79k
    if ((*revertMask & URI_NORMALIZE_HOST) == 0) {
406
5.60k
        if (uri->hostData.ipFuture.first != NULL) {
407
            /* IPvFuture */
408
0
            if (!URI_FUNC(MakeRangeOwner)(revertMask, URI_NORMALIZE_HOST,
409
0
                        &(uri->hostData.ipFuture), memory)) {
410
0
                return URI_FALSE; /* Raises malloc error */
411
0
            }
412
0
            uri->hostText.first = uri->hostData.ipFuture.first;
413
0
            uri->hostText.afterLast = uri->hostData.ipFuture.afterLast;
414
5.60k
        } else if (uri->hostText.first != NULL) {
415
            /* Regname */
416
53
            if (!URI_FUNC(MakeRangeOwner)(
417
53
                        revertMask, URI_NORMALIZE_HOST, &(uri->hostText), memory)) {
418
0
                return URI_FALSE; /* Raises malloc error */
419
0
            }
420
53
        }
421
5.60k
    }
422
423
    /* Path */
424
6.79k
    if ((*revertMask & URI_NORMALIZE_PATH) == 0) {
425
0
        while (walker != NULL) {
426
0
            if (!URI_FUNC(MakeRangeOwner)(revertMask, 0, &(walker->text), memory)) {
427
                /* Free allocations done so far and kill path */
428
429
                /* Kill path to one before walker (if any) */
430
0
                URI_TYPE(PathSegment) * ranger = uri->pathHead;
431
0
                while (ranger != walker) {
432
0
                    URI_TYPE(PathSegment) * const next = ranger->next;
433
0
                    if ((ranger->text.first != NULL) && (ranger->text.afterLast != NULL)
434
0
                            && (ranger->text.afterLast > ranger->text.first)) {
435
0
                        memory->free(memory, (URI_CHAR *)ranger->text.first);
436
0
                    }
437
0
                    memory->free(memory, ranger);
438
0
                    ranger = next;
439
0
                }
440
441
                /* Kill path from walker */
442
0
                while (walker != NULL) {
443
0
                    URI_TYPE(PathSegment) * const next = walker->next;
444
0
                    memory->free(memory, walker);
445
0
                    walker = next;
446
0
                }
447
448
0
                uri->pathHead = NULL;
449
0
                uri->pathTail = NULL;
450
0
                return URI_FALSE; /* Raises malloc error */
451
0
            }
452
0
            walker = walker->next;
453
0
        }
454
0
        *revertMask |= URI_NORMALIZE_PATH;
455
0
    }
456
457
    /* Port text, must come last so we don't have to undo that one if it fails. *
458
     * Otherwise we would need and extra enum flag for it although the port      *
459
     * cannot go unnormalized...                                                */
460
6.79k
    if (!URI_FUNC(MakeRangeOwner)(revertMask, 0, &(uri->portText), memory)) {
461
0
        return URI_FALSE; /* Raises malloc error */
462
0
    }
463
464
6.79k
    return URI_TRUE;
465
6.79k
}
Unexecuted instantiation: UriNormalize.c:uriMakeOwnerEngineW
466
467
0
unsigned int URI_FUNC(NormalizeSyntaxMaskRequired)(const URI_TYPE(Uri) * uri) {
468
0
    unsigned int outMask = URI_NORMALIZED; /* for NULL uri */
469
0
    URI_FUNC(NormalizeSyntaxMaskRequiredEx)(uri, &outMask);
470
0
    return outMask;
471
0
}
Unexecuted instantiation: uriNormalizeSyntaxMaskRequiredA
Unexecuted instantiation: uriNormalizeSyntaxMaskRequiredW
472
473
int URI_FUNC(NormalizeSyntaxMaskRequiredEx)(
474
6.79k
        const URI_TYPE(Uri) * uri, unsigned int * outMask) {
475
6.79k
    UriMemoryManager * const memory = NULL; /* no use of memory manager */
476
477
6.79k
#  if defined(__GNUC__) \
478
6.79k
          && ((__GNUC__ > 4) \
479
6.79k
                  || ((__GNUC__ == 4) && defined(__GNUC_MINOR__) \
480
6.79k
                          && (__GNUC_MINOR__ >= 2)))
481
    /* Slower code that fixes a warning, not sure if this is a smart idea */
482
6.79k
    URI_TYPE(Uri) writeableClone;
483
6.79k
#  endif
484
485
6.79k
    if ((uri == NULL) || (outMask == NULL)) {
486
0
        return URI_ERROR_NULL;
487
0
    }
488
489
6.79k
#  if defined(__GNUC__) \
490
6.79k
          && ((__GNUC__ > 4) \
491
6.79k
                  || ((__GNUC__ == 4) && defined(__GNUC_MINOR__) \
492
6.79k
                          && (__GNUC_MINOR__ >= 2)))
493
    /* Slower code that fixes a warning, not sure if this is a smart idea */
494
6.79k
    memcpy(&writeableClone, uri, 1 * sizeof(URI_TYPE(Uri)));
495
6.79k
    URI_FUNC(NormalizeSyntaxEngine)(&writeableClone, 0, outMask, memory);
496
#  else
497
    URI_FUNC(NormalizeSyntaxEngine)((URI_TYPE(Uri) *)uri, 0, outMask, memory);
498
#  endif
499
6.79k
    return URI_SUCCESS;
500
6.79k
}
uriNormalizeSyntaxMaskRequiredExA
Line
Count
Source
474
6.79k
        const URI_TYPE(Uri) * uri, unsigned int * outMask) {
475
6.79k
    UriMemoryManager * const memory = NULL; /* no use of memory manager */
476
477
6.79k
#  if defined(__GNUC__) \
478
6.79k
          && ((__GNUC__ > 4) \
479
6.79k
                  || ((__GNUC__ == 4) && defined(__GNUC_MINOR__) \
480
6.79k
                          && (__GNUC_MINOR__ >= 2)))
481
    /* Slower code that fixes a warning, not sure if this is a smart idea */
482
6.79k
    URI_TYPE(Uri) writeableClone;
483
6.79k
#  endif
484
485
6.79k
    if ((uri == NULL) || (outMask == NULL)) {
486
0
        return URI_ERROR_NULL;
487
0
    }
488
489
6.79k
#  if defined(__GNUC__) \
490
6.79k
          && ((__GNUC__ > 4) \
491
6.79k
                  || ((__GNUC__ == 4) && defined(__GNUC_MINOR__) \
492
6.79k
                          && (__GNUC_MINOR__ >= 2)))
493
    /* Slower code that fixes a warning, not sure if this is a smart idea */
494
6.79k
    memcpy(&writeableClone, uri, 1 * sizeof(URI_TYPE(Uri)));
495
6.79k
    URI_FUNC(NormalizeSyntaxEngine)(&writeableClone, 0, outMask, memory);
496
#  else
497
    URI_FUNC(NormalizeSyntaxEngine)((URI_TYPE(Uri) *)uri, 0, outMask, memory);
498
#  endif
499
6.79k
    return URI_SUCCESS;
500
6.79k
}
Unexecuted instantiation: uriNormalizeSyntaxMaskRequiredExW
501
502
6.79k
int URI_FUNC(NormalizeSyntaxEx)(URI_TYPE(Uri) * uri, unsigned int mask) {
503
6.79k
    return URI_FUNC(NormalizeSyntaxExMm)(uri, mask, NULL);
504
6.79k
}
uriNormalizeSyntaxExA
Line
Count
Source
502
6.79k
int URI_FUNC(NormalizeSyntaxEx)(URI_TYPE(Uri) * uri, unsigned int mask) {
503
6.79k
    return URI_FUNC(NormalizeSyntaxExMm)(uri, mask, NULL);
504
6.79k
}
Unexecuted instantiation: uriNormalizeSyntaxExW
505
506
int URI_FUNC(NormalizeSyntaxExMm)(
507
6.79k
        URI_TYPE(Uri) * uri, unsigned int mask, UriMemoryManager * memory) {
508
6.79k
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
509
6.79k
    return URI_FUNC(NormalizeSyntaxEngine)(uri, mask, NULL, memory);
510
6.79k
}
uriNormalizeSyntaxExMmA
Line
Count
Source
507
6.79k
        URI_TYPE(Uri) * uri, unsigned int mask, UriMemoryManager * memory) {
508
6.79k
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
509
6.79k
    return URI_FUNC(NormalizeSyntaxEngine)(uri, mask, NULL, memory);
510
6.79k
}
Unexecuted instantiation: uriNormalizeSyntaxExMmW
511
512
6.79k
int URI_FUNC(NormalizeSyntax)(URI_TYPE(Uri) * uri) {
513
6.79k
    return URI_FUNC(NormalizeSyntaxEx)(uri, (unsigned int)-1);
514
6.79k
}
uriNormalizeSyntaxA
Line
Count
Source
512
6.79k
int URI_FUNC(NormalizeSyntax)(URI_TYPE(Uri) * uri) {
513
6.79k
    return URI_FUNC(NormalizeSyntaxEx)(uri, (unsigned int)-1);
514
6.79k
}
Unexecuted instantiation: uriNormalizeSyntaxW
515
516
static const URI_CHAR * URI_FUNC(PastLeadingZeros)(
517
135
        const URI_CHAR * first, const URI_CHAR * afterLast) {
518
135
    assert(first != NULL);
519
135
    assert(afterLast != NULL);
520
135
    assert(first != afterLast);
521
522
    /* Find the first non-zero character */
523
135
    const URI_CHAR * remainderFirst = first;
524
2.79k
    while ((remainderFirst < afterLast) && (remainderFirst[0] == _UT('0'))) {
525
2.65k
        remainderFirst++;
526
2.65k
    }
527
528
    /* Is the string /all/ zeros? */
529
135
    if (remainderFirst == afterLast) {
530
        /* Yes, and length is >=1 because we ruled out the empty string earlier;
531
         * pull back onto rightmost zero */
532
23
        assert(remainderFirst > first);
533
23
        remainderFirst--;
534
23
        assert(remainderFirst[0] == _UT('0'));
535
23
    }
536
537
135
    return remainderFirst;
538
135
}
UriNormalize.c:uriPastLeadingZerosA
Line
Count
Source
517
135
        const URI_CHAR * first, const URI_CHAR * afterLast) {
518
135
    assert(first != NULL);
519
135
    assert(afterLast != NULL);
520
135
    assert(first != afterLast);
521
522
    /* Find the first non-zero character */
523
135
    const URI_CHAR * remainderFirst = first;
524
2.79k
    while ((remainderFirst < afterLast) && (remainderFirst[0] == _UT('0'))) {
525
2.65k
        remainderFirst++;
526
2.65k
    }
527
528
    /* Is the string /all/ zeros? */
529
135
    if (remainderFirst == afterLast) {
530
        /* Yes, and length is >=1 because we ruled out the empty string earlier;
531
         * pull back onto rightmost zero */
532
23
        assert(remainderFirst > first);
533
23
        remainderFirst--;
534
23
        assert(remainderFirst[0] == _UT('0'));
535
23
    }
536
537
135
    return remainderFirst;
538
135
}
Unexecuted instantiation: UriNormalize.c:uriPastLeadingZerosW
539
540
static void URI_FUNC(DropLeadingZerosInplace)(
541
0
        URI_CHAR * first, const URI_CHAR ** afterLast) {
542
0
    assert(first != NULL);
543
0
    assert(afterLast != NULL);
544
0
    assert(*afterLast != NULL);
545
546
0
    if (first == *afterLast) {
547
0
        return;
548
0
    }
549
550
0
    const URI_CHAR * const remainderFirst = URI_FUNC(PastLeadingZeros)(first, *afterLast);
551
552
0
    if (remainderFirst > first) {
553
0
        const size_t remainderLen = *afterLast - remainderFirst;
554
0
        memmove(first, remainderFirst, remainderLen * sizeof(URI_CHAR));
555
0
        first[remainderLen] = _UT('\0');
556
0
        *afterLast = first + remainderLen;
557
0
    }
558
0
}
Unexecuted instantiation: UriNormalize.c:uriDropLeadingZerosInplaceA
Unexecuted instantiation: UriNormalize.c:uriDropLeadingZerosInplaceW
559
560
static void URI_FUNC(AdvancePastLeadingZeros)(
561
182
        const URI_CHAR ** first, const URI_CHAR * afterLast) {
562
182
    assert(first != NULL);
563
182
    assert(*first != NULL);
564
182
    assert(afterLast != NULL);
565
566
182
    if (*first == afterLast) {
567
47
        return;
568
47
    }
569
570
135
    const URI_CHAR * const remainderFirst = URI_FUNC(PastLeadingZeros)(*first, afterLast);
571
572
    /* Cut off leading zeros */
573
135
    *first = remainderFirst;
574
135
}
UriNormalize.c:uriAdvancePastLeadingZerosA
Line
Count
Source
561
182
        const URI_CHAR ** first, const URI_CHAR * afterLast) {
562
182
    assert(first != NULL);
563
182
    assert(*first != NULL);
564
182
    assert(afterLast != NULL);
565
566
182
    if (*first == afterLast) {
567
47
        return;
568
47
    }
569
570
135
    const URI_CHAR * const remainderFirst = URI_FUNC(PastLeadingZeros)(*first, afterLast);
571
572
    /* Cut off leading zeros */
573
135
    *first = remainderFirst;
574
135
}
Unexecuted instantiation: UriNormalize.c:uriAdvancePastLeadingZerosW
575
576
static URI_INLINE int URI_FUNC(NormalizeSyntaxEngine)(URI_TYPE(Uri) * uri,
577
13.5k
        unsigned int inMask, unsigned int * outMask, UriMemoryManager * memory) {
578
13.5k
    unsigned int revertMask = URI_NORMALIZED;
579
580
    /* Not just doing inspection? -> memory manager required! */
581
13.5k
    if (outMask == NULL) {
582
6.79k
        assert(memory != NULL);
583
6.79k
    }
584
585
13.5k
    if (uri == NULL) {
586
0
        if (outMask != NULL) {
587
0
            *outMask = URI_NORMALIZED;
588
0
            return URI_SUCCESS;
589
0
        } else {
590
0
            return URI_ERROR_NULL;
591
0
        }
592
0
    }
593
594
13.5k
    if (outMask != NULL) {
595
        /* Reset mask */
596
6.79k
        *outMask = URI_NORMALIZED;
597
6.79k
    } else if (inMask == URI_NORMALIZED) {
598
        /* Nothing to do */
599
0
        return URI_SUCCESS;
600
0
    }
601
602
    /* Scheme, host */
603
13.5k
    if (outMask != NULL) {
604
6.79k
        const UriBool normalizeScheme = URI_FUNC(ContainsUppercaseLetters)(
605
6.79k
                uri->scheme.first, uri->scheme.afterLast);
606
6.79k
        const UriBool normalizeHostCase = URI_FUNC(ContainsUppercaseLetters)(
607
6.79k
                uri->hostText.first, uri->hostText.afterLast);
608
6.79k
        if (normalizeScheme) {
609
206
            *outMask |= URI_NORMALIZE_SCHEME;
610
206
        }
611
612
6.79k
        if (normalizeHostCase) {
613
425
            *outMask |= URI_NORMALIZE_HOST;
614
6.37k
        } else {
615
6.37k
            const UriBool normalizeHostPrecent = URI_FUNC(ContainsUglyPercentEncoding)(
616
6.37k
                    uri->hostText.first, uri->hostText.afterLast);
617
6.37k
            if (normalizeHostPrecent) {
618
11
                *outMask |= URI_NORMALIZE_HOST;
619
11
            }
620
6.37k
        }
621
6.79k
    } else {
622
        /* Scheme */
623
6.79k
        if ((inMask & URI_NORMALIZE_SCHEME) && (uri->scheme.first != NULL)) {
624
511
            if (uri->owner) {
625
0
                URI_FUNC(LowercaseInplace)(uri->scheme.first, uri->scheme.afterLast);
626
511
            } else {
627
511
                if (!URI_FUNC(LowercaseMalloc)(
628
511
                            &(uri->scheme.first), &(uri->scheme.afterLast), memory)) {
629
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
630
0
                    return URI_ERROR_MALLOC;
631
0
                }
632
511
                revertMask |= URI_NORMALIZE_SCHEME;
633
511
            }
634
511
        }
635
636
        /* Host */
637
6.79k
        if (inMask & URI_NORMALIZE_HOST) {
638
6.79k
            if (uri->hostData.ipFuture.first != NULL) {
639
                /* IPvFuture */
640
134
                if (uri->owner) {
641
0
                    URI_FUNC(LowercaseInplace)(uri->hostData.ipFuture.first,
642
0
                            uri->hostData.ipFuture.afterLast);
643
134
                } else {
644
134
                    if (!URI_FUNC(LowercaseMalloc)(&(uri->hostData.ipFuture.first),
645
134
                                &(uri->hostData.ipFuture.afterLast), memory)) {
646
0
                        URI_FUNC(PreventLeakage)(uri, revertMask, memory);
647
0
                        return URI_ERROR_MALLOC;
648
0
                    }
649
134
                    revertMask |= URI_NORMALIZE_HOST;
650
134
                }
651
134
                uri->hostText.first = uri->hostData.ipFuture.first;
652
134
                uri->hostText.afterLast = uri->hostData.ipFuture.afterLast;
653
6.66k
            } else if ((uri->hostText.first != NULL) && (uri->hostData.ip4 == NULL)) {
654
                /* Regname or IPv6 */
655
1.06k
                if (uri->owner) {
656
0
                    URI_FUNC(FixPercentEncodingInplace)(
657
0
                            uri->hostText.first, &(uri->hostText.afterLast));
658
1.06k
                } else {
659
1.06k
                    if (!URI_FUNC(FixPercentEncodingMalloc)(&(uri->hostText.first),
660
1.06k
                                &(uri->hostText.afterLast), memory)) {
661
0
                        URI_FUNC(PreventLeakage)(uri, revertMask, memory);
662
0
                        return URI_ERROR_MALLOC;
663
0
                    }
664
1.06k
                    revertMask |= URI_NORMALIZE_HOST;
665
1.06k
                }
666
667
1.06k
                URI_FUNC(LowercaseInplaceExceptPercentEncoding)(
668
1.06k
                        uri->hostText.first, uri->hostText.afterLast);
669
1.06k
            }
670
6.79k
        }
671
6.79k
    }
672
673
    /* Port */
674
13.5k
    if (outMask != NULL) {
675
        /* Is there a port even? */
676
6.79k
        if (uri->portText.first != NULL) {
677
            /* Determine whether the port is already normalized, i.e. either "", "0" or no
678
             * leading zeros */
679
182
            const size_t portLen = uri->portText.afterLast - uri->portText.first;
680
182
            if ((portLen > 1) && (uri->portText.first[0] == _UT('0'))) {
681
21
                *outMask |= URI_NORMALIZE_PORT;
682
21
            }
683
182
        }
684
6.79k
    } else {
685
        /* Normalize the port, i.e. drop leading zeros (except for string "0") */
686
6.79k
        if ((inMask & URI_NORMALIZE_PORT) && (uri->portText.first != NULL)) {
687
182
            if (uri->owner) {
688
0
                URI_FUNC(DropLeadingZerosInplace)(
689
0
                        (URI_CHAR *)uri->portText.first, &(uri->portText.afterLast));
690
182
            } else {
691
182
                URI_FUNC(AdvancePastLeadingZeros)(
692
182
                        &(uri->portText.first), uri->portText.afterLast);
693
182
            }
694
182
        }
695
6.79k
    }
696
697
    /* User info */
698
13.5k
    if (outMask != NULL) {
699
6.79k
        const UriBool normalizeUserInfo = URI_FUNC(ContainsUglyPercentEncoding)(
700
6.79k
                uri->userInfo.first, uri->userInfo.afterLast);
701
6.79k
        if (normalizeUserInfo) {
702
78
            *outMask |= URI_NORMALIZE_USER_INFO;
703
78
        }
704
6.79k
    } else {
705
6.79k
        if ((inMask & URI_NORMALIZE_USER_INFO) && (uri->userInfo.first != NULL)) {
706
382
            if (uri->owner) {
707
0
                URI_FUNC(FixPercentEncodingInplace)(
708
0
                        uri->userInfo.first, &(uri->userInfo.afterLast));
709
382
            } else {
710
382
                if (!URI_FUNC(FixPercentEncodingMalloc)(
711
382
                            &(uri->userInfo.first), &(uri->userInfo.afterLast), memory)) {
712
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
713
0
                    return URI_ERROR_MALLOC;
714
0
                }
715
382
                revertMask |= URI_NORMALIZE_USER_INFO;
716
382
            }
717
382
        }
718
6.79k
    }
719
720
    /* Path */
721
13.5k
    if (outMask != NULL) {
722
6.79k
        const URI_TYPE(PathSegment) * walker = uri->pathHead;
723
15.1k
        while (walker != NULL) {
724
8.74k
            const URI_CHAR * const first = walker->text.first;
725
8.74k
            const URI_CHAR * const afterLast = walker->text.afterLast;
726
8.74k
            if ((first != NULL) && (afterLast != NULL) && (afterLast > first)
727
5.08k
                    && ((((afterLast - first) == 1) && (first[0] == _UT('.')))
728
4.98k
                            || (((afterLast - first) == 2) && (first[0] == _UT('.'))
729
393
                                    && (first[1] == _UT('.')))
730
4.84k
                            || URI_FUNC(ContainsUglyPercentEncoding)(first, afterLast))) {
731
386
                *outMask |= URI_NORMALIZE_PATH;
732
386
                break;
733
386
            }
734
8.35k
            walker = walker->next;
735
8.35k
        }
736
6.79k
    } else if (inMask & URI_NORMALIZE_PATH) {
737
6.79k
        URI_TYPE(PathSegment) * walker;
738
6.79k
        const UriBool relative = ((uri->scheme.first == NULL) && !uri->absolutePath)
739
6.79k
                                         ? URI_TRUE
740
6.79k
                                         : URI_FALSE;
741
742
        /* Fix percent-encoding for each segment */
743
6.79k
        walker = uri->pathHead;
744
6.79k
        if (uri->owner) {
745
0
            while (walker != NULL) {
746
0
                URI_FUNC(FixPercentEncodingInplace)(
747
0
                        walker->text.first, &(walker->text.afterLast));
748
0
                walker = walker->next;
749
0
            }
750
6.79k
        } else {
751
27.1k
            while (walker != NULL) {
752
20.3k
                if (!URI_FUNC(FixPercentEncodingMalloc)(
753
20.3k
                            &(walker->text.first), &(walker->text.afterLast), memory)) {
754
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
755
0
                    return URI_ERROR_MALLOC;
756
0
                }
757
20.3k
                walker = walker->next;
758
20.3k
            }
759
6.79k
            revertMask |= URI_NORMALIZE_PATH;
760
6.79k
        }
761
762
        /* 6.2.2.3 Path Segment Normalization */
763
6.79k
        if (!URI_FUNC(RemoveDotSegmentsEx)(uri, relative,
764
6.79k
                    (uri->owner == URI_TRUE) || ((revertMask & URI_NORMALIZE_PATH) != 0),
765
6.79k
                    memory)) {
766
0
            URI_FUNC(PreventLeakage)(uri, revertMask, memory);
767
0
            return URI_ERROR_MALLOC;
768
0
        }
769
6.79k
        URI_FUNC(FixEmptyTrailSegment)(uri, memory);
770
6.79k
    }
771
772
    /* Query, fragment */
773
13.5k
    if (outMask != NULL) {
774
6.79k
        const UriBool normalizeQuery = URI_FUNC(ContainsUglyPercentEncoding)(
775
6.79k
                uri->query.first, uri->query.afterLast);
776
6.79k
        const UriBool normalizeFragment = URI_FUNC(ContainsUglyPercentEncoding)(
777
6.79k
                uri->fragment.first, uri->fragment.afterLast);
778
6.79k
        if (normalizeQuery) {
779
31
            *outMask |= URI_NORMALIZE_QUERY;
780
31
        }
781
782
6.79k
        if (normalizeFragment) {
783
21
            *outMask |= URI_NORMALIZE_FRAGMENT;
784
21
        }
785
6.79k
    } else {
786
        /* Query */
787
6.79k
        if ((inMask & URI_NORMALIZE_QUERY) && (uri->query.first != NULL)) {
788
250
            if (uri->owner) {
789
0
                URI_FUNC(FixPercentEncodingInplace)(
790
0
                        uri->query.first, &(uri->query.afterLast));
791
250
            } else {
792
250
                if (!URI_FUNC(FixPercentEncodingMalloc)(
793
250
                            &(uri->query.first), &(uri->query.afterLast), memory)) {
794
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
795
0
                    return URI_ERROR_MALLOC;
796
0
                }
797
250
                revertMask |= URI_NORMALIZE_QUERY;
798
250
            }
799
250
        }
800
801
        /* Fragment */
802
6.79k
        if ((inMask & URI_NORMALIZE_FRAGMENT) && (uri->fragment.first != NULL)) {
803
196
            if (uri->owner) {
804
0
                URI_FUNC(FixPercentEncodingInplace)(
805
0
                        uri->fragment.first, &(uri->fragment.afterLast));
806
196
            } else {
807
196
                if (!URI_FUNC(FixPercentEncodingMalloc)(
808
196
                            &(uri->fragment.first), &(uri->fragment.afterLast), memory)) {
809
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
810
0
                    return URI_ERROR_MALLOC;
811
0
                }
812
196
                revertMask |= URI_NORMALIZE_FRAGMENT;
813
196
            }
814
196
        }
815
6.79k
    }
816
817
    /* Dup all not duped yet */
818
13.5k
    if ((outMask == NULL) && !uri->owner) {
819
6.79k
        if (!URI_FUNC(MakeOwnerEngine)(uri, &revertMask, memory)) {
820
0
            URI_FUNC(PreventLeakage)(uri, revertMask, memory);
821
0
            return URI_ERROR_MALLOC;
822
0
        }
823
6.79k
        uri->owner = URI_TRUE;
824
6.79k
    }
825
826
13.5k
    return URI_SUCCESS;
827
13.5k
}
UriNormalize.c:uriNormalizeSyntaxEngineA
Line
Count
Source
577
13.5k
        unsigned int inMask, unsigned int * outMask, UriMemoryManager * memory) {
578
13.5k
    unsigned int revertMask = URI_NORMALIZED;
579
580
    /* Not just doing inspection? -> memory manager required! */
581
13.5k
    if (outMask == NULL) {
582
6.79k
        assert(memory != NULL);
583
6.79k
    }
584
585
13.5k
    if (uri == NULL) {
586
0
        if (outMask != NULL) {
587
0
            *outMask = URI_NORMALIZED;
588
0
            return URI_SUCCESS;
589
0
        } else {
590
0
            return URI_ERROR_NULL;
591
0
        }
592
0
    }
593
594
13.5k
    if (outMask != NULL) {
595
        /* Reset mask */
596
6.79k
        *outMask = URI_NORMALIZED;
597
6.79k
    } else if (inMask == URI_NORMALIZED) {
598
        /* Nothing to do */
599
0
        return URI_SUCCESS;
600
0
    }
601
602
    /* Scheme, host */
603
13.5k
    if (outMask != NULL) {
604
6.79k
        const UriBool normalizeScheme = URI_FUNC(ContainsUppercaseLetters)(
605
6.79k
                uri->scheme.first, uri->scheme.afterLast);
606
6.79k
        const UriBool normalizeHostCase = URI_FUNC(ContainsUppercaseLetters)(
607
6.79k
                uri->hostText.first, uri->hostText.afterLast);
608
6.79k
        if (normalizeScheme) {
609
206
            *outMask |= URI_NORMALIZE_SCHEME;
610
206
        }
611
612
6.79k
        if (normalizeHostCase) {
613
425
            *outMask |= URI_NORMALIZE_HOST;
614
6.37k
        } else {
615
6.37k
            const UriBool normalizeHostPrecent = URI_FUNC(ContainsUglyPercentEncoding)(
616
6.37k
                    uri->hostText.first, uri->hostText.afterLast);
617
6.37k
            if (normalizeHostPrecent) {
618
11
                *outMask |= URI_NORMALIZE_HOST;
619
11
            }
620
6.37k
        }
621
6.79k
    } else {
622
        /* Scheme */
623
6.79k
        if ((inMask & URI_NORMALIZE_SCHEME) && (uri->scheme.first != NULL)) {
624
511
            if (uri->owner) {
625
0
                URI_FUNC(LowercaseInplace)(uri->scheme.first, uri->scheme.afterLast);
626
511
            } else {
627
511
                if (!URI_FUNC(LowercaseMalloc)(
628
511
                            &(uri->scheme.first), &(uri->scheme.afterLast), memory)) {
629
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
630
0
                    return URI_ERROR_MALLOC;
631
0
                }
632
511
                revertMask |= URI_NORMALIZE_SCHEME;
633
511
            }
634
511
        }
635
636
        /* Host */
637
6.79k
        if (inMask & URI_NORMALIZE_HOST) {
638
6.79k
            if (uri->hostData.ipFuture.first != NULL) {
639
                /* IPvFuture */
640
134
                if (uri->owner) {
641
0
                    URI_FUNC(LowercaseInplace)(uri->hostData.ipFuture.first,
642
0
                            uri->hostData.ipFuture.afterLast);
643
134
                } else {
644
134
                    if (!URI_FUNC(LowercaseMalloc)(&(uri->hostData.ipFuture.first),
645
134
                                &(uri->hostData.ipFuture.afterLast), memory)) {
646
0
                        URI_FUNC(PreventLeakage)(uri, revertMask, memory);
647
0
                        return URI_ERROR_MALLOC;
648
0
                    }
649
134
                    revertMask |= URI_NORMALIZE_HOST;
650
134
                }
651
134
                uri->hostText.first = uri->hostData.ipFuture.first;
652
134
                uri->hostText.afterLast = uri->hostData.ipFuture.afterLast;
653
6.66k
            } else if ((uri->hostText.first != NULL) && (uri->hostData.ip4 == NULL)) {
654
                /* Regname or IPv6 */
655
1.06k
                if (uri->owner) {
656
0
                    URI_FUNC(FixPercentEncodingInplace)(
657
0
                            uri->hostText.first, &(uri->hostText.afterLast));
658
1.06k
                } else {
659
1.06k
                    if (!URI_FUNC(FixPercentEncodingMalloc)(&(uri->hostText.first),
660
1.06k
                                &(uri->hostText.afterLast), memory)) {
661
0
                        URI_FUNC(PreventLeakage)(uri, revertMask, memory);
662
0
                        return URI_ERROR_MALLOC;
663
0
                    }
664
1.06k
                    revertMask |= URI_NORMALIZE_HOST;
665
1.06k
                }
666
667
1.06k
                URI_FUNC(LowercaseInplaceExceptPercentEncoding)(
668
1.06k
                        uri->hostText.first, uri->hostText.afterLast);
669
1.06k
            }
670
6.79k
        }
671
6.79k
    }
672
673
    /* Port */
674
13.5k
    if (outMask != NULL) {
675
        /* Is there a port even? */
676
6.79k
        if (uri->portText.first != NULL) {
677
            /* Determine whether the port is already normalized, i.e. either "", "0" or no
678
             * leading zeros */
679
182
            const size_t portLen = uri->portText.afterLast - uri->portText.first;
680
182
            if ((portLen > 1) && (uri->portText.first[0] == _UT('0'))) {
681
21
                *outMask |= URI_NORMALIZE_PORT;
682
21
            }
683
182
        }
684
6.79k
    } else {
685
        /* Normalize the port, i.e. drop leading zeros (except for string "0") */
686
6.79k
        if ((inMask & URI_NORMALIZE_PORT) && (uri->portText.first != NULL)) {
687
182
            if (uri->owner) {
688
0
                URI_FUNC(DropLeadingZerosInplace)(
689
0
                        (URI_CHAR *)uri->portText.first, &(uri->portText.afterLast));
690
182
            } else {
691
182
                URI_FUNC(AdvancePastLeadingZeros)(
692
182
                        &(uri->portText.first), uri->portText.afterLast);
693
182
            }
694
182
        }
695
6.79k
    }
696
697
    /* User info */
698
13.5k
    if (outMask != NULL) {
699
6.79k
        const UriBool normalizeUserInfo = URI_FUNC(ContainsUglyPercentEncoding)(
700
6.79k
                uri->userInfo.first, uri->userInfo.afterLast);
701
6.79k
        if (normalizeUserInfo) {
702
78
            *outMask |= URI_NORMALIZE_USER_INFO;
703
78
        }
704
6.79k
    } else {
705
6.79k
        if ((inMask & URI_NORMALIZE_USER_INFO) && (uri->userInfo.first != NULL)) {
706
382
            if (uri->owner) {
707
0
                URI_FUNC(FixPercentEncodingInplace)(
708
0
                        uri->userInfo.first, &(uri->userInfo.afterLast));
709
382
            } else {
710
382
                if (!URI_FUNC(FixPercentEncodingMalloc)(
711
382
                            &(uri->userInfo.first), &(uri->userInfo.afterLast), memory)) {
712
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
713
0
                    return URI_ERROR_MALLOC;
714
0
                }
715
382
                revertMask |= URI_NORMALIZE_USER_INFO;
716
382
            }
717
382
        }
718
6.79k
    }
719
720
    /* Path */
721
13.5k
    if (outMask != NULL) {
722
6.79k
        const URI_TYPE(PathSegment) * walker = uri->pathHead;
723
15.1k
        while (walker != NULL) {
724
8.74k
            const URI_CHAR * const first = walker->text.first;
725
8.74k
            const URI_CHAR * const afterLast = walker->text.afterLast;
726
8.74k
            if ((first != NULL) && (afterLast != NULL) && (afterLast > first)
727
5.08k
                    && ((((afterLast - first) == 1) && (first[0] == _UT('.')))
728
4.98k
                            || (((afterLast - first) == 2) && (first[0] == _UT('.'))
729
393
                                    && (first[1] == _UT('.')))
730
4.84k
                            || URI_FUNC(ContainsUglyPercentEncoding)(first, afterLast))) {
731
386
                *outMask |= URI_NORMALIZE_PATH;
732
386
                break;
733
386
            }
734
8.35k
            walker = walker->next;
735
8.35k
        }
736
6.79k
    } else if (inMask & URI_NORMALIZE_PATH) {
737
6.79k
        URI_TYPE(PathSegment) * walker;
738
6.79k
        const UriBool relative = ((uri->scheme.first == NULL) && !uri->absolutePath)
739
6.79k
                                         ? URI_TRUE
740
6.79k
                                         : URI_FALSE;
741
742
        /* Fix percent-encoding for each segment */
743
6.79k
        walker = uri->pathHead;
744
6.79k
        if (uri->owner) {
745
0
            while (walker != NULL) {
746
0
                URI_FUNC(FixPercentEncodingInplace)(
747
0
                        walker->text.first, &(walker->text.afterLast));
748
0
                walker = walker->next;
749
0
            }
750
6.79k
        } else {
751
27.1k
            while (walker != NULL) {
752
20.3k
                if (!URI_FUNC(FixPercentEncodingMalloc)(
753
20.3k
                            &(walker->text.first), &(walker->text.afterLast), memory)) {
754
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
755
0
                    return URI_ERROR_MALLOC;
756
0
                }
757
20.3k
                walker = walker->next;
758
20.3k
            }
759
6.79k
            revertMask |= URI_NORMALIZE_PATH;
760
6.79k
        }
761
762
        /* 6.2.2.3 Path Segment Normalization */
763
6.79k
        if (!URI_FUNC(RemoveDotSegmentsEx)(uri, relative,
764
6.79k
                    (uri->owner == URI_TRUE) || ((revertMask & URI_NORMALIZE_PATH) != 0),
765
6.79k
                    memory)) {
766
0
            URI_FUNC(PreventLeakage)(uri, revertMask, memory);
767
0
            return URI_ERROR_MALLOC;
768
0
        }
769
6.79k
        URI_FUNC(FixEmptyTrailSegment)(uri, memory);
770
6.79k
    }
771
772
    /* Query, fragment */
773
13.5k
    if (outMask != NULL) {
774
6.79k
        const UriBool normalizeQuery = URI_FUNC(ContainsUglyPercentEncoding)(
775
6.79k
                uri->query.first, uri->query.afterLast);
776
6.79k
        const UriBool normalizeFragment = URI_FUNC(ContainsUglyPercentEncoding)(
777
6.79k
                uri->fragment.first, uri->fragment.afterLast);
778
6.79k
        if (normalizeQuery) {
779
31
            *outMask |= URI_NORMALIZE_QUERY;
780
31
        }
781
782
6.79k
        if (normalizeFragment) {
783
21
            *outMask |= URI_NORMALIZE_FRAGMENT;
784
21
        }
785
6.79k
    } else {
786
        /* Query */
787
6.79k
        if ((inMask & URI_NORMALIZE_QUERY) && (uri->query.first != NULL)) {
788
250
            if (uri->owner) {
789
0
                URI_FUNC(FixPercentEncodingInplace)(
790
0
                        uri->query.first, &(uri->query.afterLast));
791
250
            } else {
792
250
                if (!URI_FUNC(FixPercentEncodingMalloc)(
793
250
                            &(uri->query.first), &(uri->query.afterLast), memory)) {
794
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
795
0
                    return URI_ERROR_MALLOC;
796
0
                }
797
250
                revertMask |= URI_NORMALIZE_QUERY;
798
250
            }
799
250
        }
800
801
        /* Fragment */
802
6.79k
        if ((inMask & URI_NORMALIZE_FRAGMENT) && (uri->fragment.first != NULL)) {
803
196
            if (uri->owner) {
804
0
                URI_FUNC(FixPercentEncodingInplace)(
805
0
                        uri->fragment.first, &(uri->fragment.afterLast));
806
196
            } else {
807
196
                if (!URI_FUNC(FixPercentEncodingMalloc)(
808
196
                            &(uri->fragment.first), &(uri->fragment.afterLast), memory)) {
809
0
                    URI_FUNC(PreventLeakage)(uri, revertMask, memory);
810
0
                    return URI_ERROR_MALLOC;
811
0
                }
812
196
                revertMask |= URI_NORMALIZE_FRAGMENT;
813
196
            }
814
196
        }
815
6.79k
    }
816
817
    /* Dup all not duped yet */
818
13.5k
    if ((outMask == NULL) && !uri->owner) {
819
6.79k
        if (!URI_FUNC(MakeOwnerEngine)(uri, &revertMask, memory)) {
820
0
            URI_FUNC(PreventLeakage)(uri, revertMask, memory);
821
0
            return URI_ERROR_MALLOC;
822
0
        }
823
6.79k
        uri->owner = URI_TRUE;
824
6.79k
    }
825
826
13.5k
    return URI_SUCCESS;
827
13.5k
}
Unexecuted instantiation: UriNormalize.c:uriNormalizeSyntaxEngineW
828
829
0
int URI_FUNC(MakeOwnerMm)(URI_TYPE(Uri) * uri, UriMemoryManager * memory) {
830
0
    unsigned int revertMask = URI_NORMALIZED;
831
832
0
    URI_CHECK_MEMORY_MANAGER(memory); /* may return */
833
834
0
    if (uri == NULL) {
835
0
        return URI_ERROR_NULL;
836
0
    }
837
838
0
    if (uri->owner == URI_TRUE) {
839
0
        return URI_SUCCESS;
840
0
    }
841
842
0
    if (!URI_FUNC(MakeOwnerEngine)(uri, &revertMask, memory)) {
843
0
        URI_FUNC(PreventLeakage)(uri, revertMask, memory);
844
0
        return URI_ERROR_MALLOC;
845
0
    }
846
847
0
    uri->owner = URI_TRUE;
848
849
0
    return URI_SUCCESS;
850
0
}
Unexecuted instantiation: uriMakeOwnerMmA
Unexecuted instantiation: uriMakeOwnerMmW
851
852
0
int URI_FUNC(MakeOwner)(URI_TYPE(Uri) * uri) {
853
0
    return URI_FUNC(MakeOwnerMm)(uri, NULL);
854
0
}
Unexecuted instantiation: uriMakeOwnerA
Unexecuted instantiation: uriMakeOwnerW
855
856
#endif