Bug Summary

File:root/firefox-clang/js/src/zydis/Zycore/List.c
Warning:line 637, column 34
Addition of a null pointer (from variable 'node') and a nonzero integer value results in undefined behavior

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O3 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name List.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/js/src/zydis -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/js/src/zydis -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/config/gcc_hidden.h -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/system_wrappers -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D WASM_SUPPORTS_HUGE_MEMORY -D JS_CACHEIR_SPEW -D JS_STRUCTURED_SPEW -D JS_HAS_CTYPES -D FFI_BUILDING -D EXPORT_JS_API -D MOZ_HAS_MOZGLUE -D MOZ_SUPPORT_LEAKCHECKING -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/js/src -I /root/firefox-clang/js/src -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -Wno-tautological-value-range-compare -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c /root/firefox-clang/js/src/zydis/Zycore/List.c
1/***************************************************************************************************
2
3 Zyan Core Library (Zycore-C)
4
5 Original Author : Florian Bernd
6
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24
25***************************************************************************************************/
26
27#include "zydis/Zycore/LibC.h"
28#include "zydis/Zycore/List.h"
29
30/* ============================================================================================== */
31/* Internal macros */
32/* ============================================================================================== */
33
34/**
35 * Returns a pointer to the data of the given `node`.
36 *
37 * @param node A pointer to the `ZyanNodeData` struct.
38 *
39 * @return A pointer to the data of the given `node`.
40 */
41#define ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)) \
42 ((void*)(node + 1))
43
44/* ============================================================================================== */
45/* Internal functions */
46/* ============================================================================================== */
47
48/* ---------------------------------------------------------------------------------------------- */
49/* Helper functions */
50/* ---------------------------------------------------------------------------------------------- */
51
52/**
53 * Allocates memory for a new list node.
54 *
55 * @param list A pointer to the `ZyanList` instance.
56 * @param node Receives a pointer to the new `ZyanListNode` struct.
57 *
58 * @return A zyan status code.
59 */
60static ZyanStatus ZyanListAllocateNode(ZyanList* list, ZyanListNode** node)
61{
62 ZYAN_ASSERT(list)((void) sizeof ((list) ? 1 : 0), __extension__ ({ if (list) ;
else __assert_fail ("list", "/root/firefox-clang/js/src/zydis/Zycore/List.c"
, 62, __extension__ __PRETTY_FUNCTION__); }))
;
63 ZYAN_ASSERT(node)((void) sizeof ((node) ? 1 : 0), __extension__ ({ if (node) ;
else __assert_fail ("node", "/root/firefox-clang/js/src/zydis/Zycore/List.c"
, 63, __extension__ __PRETTY_FUNCTION__); }))
;
64
65 const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL((void*)0));
66 if (is_dynamic)
67 {
68 ZYAN_ASSERT(list->allocator->allocate)((void) sizeof ((list->allocator->allocate) ? 1 : 0), __extension__
({ if (list->allocator->allocate) ; else __assert_fail
("list->allocator->allocate", "/root/firefox-clang/js/src/zydis/Zycore/List.c"
, 68, __extension__ __PRETTY_FUNCTION__); }))
;
69 ZYAN_CHECK(list->allocator->allocate(list->allocator, (void**)node,do { const ZyanStatus status_047620348 = (list->allocator->
allocate(list->allocator, (void**)node, sizeof(ZyanListNode
) + list->element_size, 1)); if (!(!((status_047620348) &
0x80000000u))) { return status_047620348; } } while (0)
70 sizeof(ZyanListNode) + list->element_size, 1))do { const ZyanStatus status_047620348 = (list->allocator->
allocate(list->allocator, (void**)node, sizeof(ZyanListNode
) + list->element_size, 1)); if (!(!((status_047620348) &
0x80000000u))) { return status_047620348; } } while (0)
;
71 } else
72 {
73 if (list->first_unused)
74 {
75 *node = list->first_unused;
76 list->first_unused = (*node)->next;
77 } else
78 {
79 const ZyanUSize size = list->size * (sizeof(ZyanListNode) + list->element_size);
80 if (size + (sizeof(ZyanListNode) + list->element_size) > list->capacity)
81 {
82 return ZYAN_STATUS_INSUFFICIENT_BUFFER_SIZE(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x09u) & 0xFFFFFu))
;
83 }
84
85 *node = (ZyanListNode*)((ZyanU8*)list->buffer + size);
86 }
87 }
88
89 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
90}
91
92/**
93 * Frees memory of a node.
94 *
95 * @param list A pointer to the `ZyanList` instance.
96 * @param node A pointer to the `ZyanListNode` struct.
97 *
98 * @return A zyan status code.
99 */
100static ZyanStatus ZyanListDeallocateNode(ZyanList* list, ZyanListNode* node)
101{
102 ZYAN_ASSERT(list)((void) sizeof ((list) ? 1 : 0), __extension__ ({ if (list) ;
else __assert_fail ("list", "/root/firefox-clang/js/src/zydis/Zycore/List.c"
, 102, __extension__ __PRETTY_FUNCTION__); }))
;
103 ZYAN_ASSERT(node)((void) sizeof ((node) ? 1 : 0), __extension__ ({ if (node) ;
else __assert_fail ("node", "/root/firefox-clang/js/src/zydis/Zycore/List.c"
, 103, __extension__ __PRETTY_FUNCTION__); }))
;
104
105 const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL((void*)0));
106 if (is_dynamic)
107 {
108 ZYAN_ASSERT(list->allocator->deallocate)((void) sizeof ((list->allocator->deallocate) ? 1 : 0),
__extension__ ({ if (list->allocator->deallocate) ; else
__assert_fail ("list->allocator->deallocate", "/root/firefox-clang/js/src/zydis/Zycore/List.c"
, 108, __extension__ __PRETTY_FUNCTION__); }))
;
109 ZYAN_CHECK(list->allocator->deallocate(list->allocator, (void*)node,do { const ZyanStatus status_047620348 = (list->allocator->
deallocate(list->allocator, (void*)node, sizeof(ZyanListNode
) + list->element_size, 1)); if (!(!((status_047620348) &
0x80000000u))) { return status_047620348; } } while (0)
110 sizeof(ZyanListNode) + list->element_size, 1))do { const ZyanStatus status_047620348 = (list->allocator->
deallocate(list->allocator, (void*)node, sizeof(ZyanListNode
) + list->element_size, 1)); if (!(!((status_047620348) &
0x80000000u))) { return status_047620348; } } while (0)
;
111 } else
112 {
113 node->next = list->first_unused;
114 list->first_unused = node;
115 }
116
117 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
118}
119
120/* ---------------------------------------------------------------------------------------------- */
121
122/* ============================================================================================== */
123/* Exported functions */
124/* ============================================================================================== */
125
126/* ---------------------------------------------------------------------------------------------- */
127/* Constructor and destructor */
128/* ---------------------------------------------------------------------------------------------- */
129
130#ifndef ZYAN_NO_LIBC
131
132ZYAN_REQUIRES_LIBC ZyanStatus ZyanListInit(ZyanList* list, ZyanUSize element_size,
133 ZyanMemberProcedure destructor)
134{
135 return ZyanListInitEx(list, element_size, destructor, ZyanAllocatorDefault());
136}
137
138#endif // ZYAN_NO_LIBC
139
140ZyanStatus ZyanListInitEx(ZyanList* list, ZyanUSize element_size, ZyanMemberProcedure destructor,
141 ZyanAllocator* allocator)
142{
143 if (!list || !element_size || !allocator)
144 {
145 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
146 }
147
148 list->allocator = allocator;
149 list->size = 0;
150 list->element_size = element_size;
151 list->destructor = destructor;
152 list->head = ZYAN_NULL((void*)0);
153 list->tail = ZYAN_NULL((void*)0);
154 list->buffer = ZYAN_NULL((void*)0);
155 list->capacity = 0;
156 list->first_unused = ZYAN_NULL((void*)0);
157
158 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
159}
160
161ZyanStatus ZyanListInitCustomBuffer(ZyanList* list, ZyanUSize element_size,
162 ZyanMemberProcedure destructor, void* buffer, ZyanUSize capacity)
163{
164 if (!list || !element_size || !buffer || !capacity)
165 {
166 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
167 }
168
169 list->allocator = ZYAN_NULL((void*)0);
170 list->size = 0;
171 list->element_size = element_size;
172 list->destructor = destructor;
173 list->head = ZYAN_NULL((void*)0);
174 list->tail = ZYAN_NULL((void*)0);
175 list->buffer = buffer;
176 list->capacity = capacity;
177 list->first_unused = ZYAN_NULL((void*)0);
178
179 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
180}
181
182ZyanStatus ZyanListDestroy(ZyanList* list)
183{
184 if (!list)
185 {
186 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
187 }
188
189 ZYAN_ASSERT(list->element_size)((void) sizeof ((list->element_size) ? 1 : 0), __extension__
({ if (list->element_size) ; else __assert_fail ("list->element_size"
, "/root/firefox-clang/js/src/zydis/Zycore/List.c", 189, __extension__
__PRETTY_FUNCTION__); }))
;
190
191 const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL((void*)0));
192 ZyanListNode* node = (is_dynamic || list->destructor) ? list->head : ZYAN_NULL((void*)0);
193 while (node)
194 {
195 if (list->destructor)
196 {
197 list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)));
198 }
199
200 ZyanListNode* const next = node->next;
201
202 if (is_dynamic)
203 {
204 ZYAN_CHECK(list->allocator->deallocate(list->allocator, node,do { const ZyanStatus status_047620348 = (list->allocator->
deallocate(list->allocator, node, sizeof(ZyanListNode) + list
->element_size, 1)); if (!(!((status_047620348) & 0x80000000u
))) { return status_047620348; } } while (0)
205 sizeof(ZyanListNode) + list->element_size, 1))do { const ZyanStatus status_047620348 = (list->allocator->
deallocate(list->allocator, node, sizeof(ZyanListNode) + list
->element_size, 1)); if (!(!((status_047620348) & 0x80000000u
))) { return status_047620348; } } while (0)
;
206 }
207
208 node = next;
209 }
210
211 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
212}
213
214/* ---------------------------------------------------------------------------------------------- */
215/* Duplication */
216/* ---------------------------------------------------------------------------------------------- */
217
218
219
220/* ---------------------------------------------------------------------------------------------- */
221/* Item access */
222/* ---------------------------------------------------------------------------------------------- */
223
224ZyanStatus ZyanListGetHeadNode(const ZyanList* list, const ZyanListNode** node)
225{
226 if (!list)
227 {
228 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
229 }
230
231 *node = list->head;
232
233 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
234}
235
236ZyanStatus ZyanListGetTailNode(const ZyanList* list, const ZyanListNode** node)
237{
238 if (!list)
239 {
240 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
241 }
242
243 *node = list->tail;
244
245 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
246}
247
248ZyanStatus ZyanListGetPrevNode(const ZyanListNode** node)
249{
250 if (!node || !*node)
251 {
252 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
253 }
254
255 *node = (*node)->prev;
256
257 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
258}
259
260ZyanStatus ZyanListGetNextNode(const ZyanListNode** node)
261{
262 if (!node || !*node)
263 {
264 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
265 }
266
267 *node = (*node)->next;
268
269 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
270}
271
272const void* ZyanListGetNodeData(const ZyanListNode* node)
273{
274 if (!node)
275 {
276 return ZYAN_NULL((void*)0);
277 }
278
279 return (const void*)ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1));
280}
281
282ZyanStatus ZyanListGetNodeDataEx(const ZyanListNode* node, const void** value)
283{
284 if (!node)
285 {
286 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
287 }
288
289 *value = (const void*)ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1));
290
291 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
292}
293
294void* ZyanListGetNodeDataMutable(const ZyanListNode* node)
295{
296 if (!node)
297 {
298 return ZYAN_NULL((void*)0);
299 }
300
301 return ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1));
302}
303
304ZyanStatus ZyanListGetNodeDataMutableEx(const ZyanListNode* node, void** value)
305{
306 if (!node)
307 {
308 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
309 }
310
311 *value = ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1));
312
313 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
314}
315
316ZyanStatus ZyanListSetNodeData(const ZyanList* list, const ZyanListNode* node, const void* value)
317{
318 if (!list || !node || !value)
319 {
320 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
321 }
322
323 if (list->destructor)
324 {
325 list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)));
326 }
327
328 ZYAN_ASSERT(list->element_size)((void) sizeof ((list->element_size) ? 1 : 0), __extension__
({ if (list->element_size) ; else __assert_fail ("list->element_size"
, "/root/firefox-clang/js/src/zydis/Zycore/List.c", 328, __extension__
__PRETTY_FUNCTION__); }))
;
329 ZYAN_MEMCPYmemcpy(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)), value, list->element_size);
330
331 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
332}
333
334/* ---------------------------------------------------------------------------------------------- */
335/* Insertion */
336/* ---------------------------------------------------------------------------------------------- */
337
338ZyanStatus ZyanListPushBack(ZyanList* list, const void* item)
339{
340 if (!list || !item)
341 {
342 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
343 }
344
345 ZyanListNode* node;
346 ZYAN_CHECK(ZyanListAllocateNode(list, &node))do { const ZyanStatus status_047620348 = (ZyanListAllocateNode
(list, &node)); if (!(!((status_047620348) & 0x80000000u
))) { return status_047620348; } } while (0)
;
347 node->prev = list->tail;
348 node->next = ZYAN_NULL((void*)0);
349
350 ZYAN_MEMCPYmemcpy(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)), item, list->element_size);
351
352 if (!list->head)
353 {
354 list->head = node;
355 list->tail = node;
356 } else
357 {
358 list->tail->next = node;
359 list->tail = node;
360 }
361 ++list->size;
362
363 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
364}
365
366ZyanStatus ZyanListPushFront(ZyanList* list, const void* item)
367{
368 if (!list || !item)
369 {
370 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
371 }
372
373 ZyanListNode* node;
374 ZYAN_CHECK(ZyanListAllocateNode(list, &node))do { const ZyanStatus status_047620348 = (ZyanListAllocateNode
(list, &node)); if (!(!((status_047620348) & 0x80000000u
))) { return status_047620348; } } while (0)
;
375 node->prev = ZYAN_NULL((void*)0);
376 node->next = list->head;
377
378 ZYAN_MEMCPYmemcpy(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)), item, list->element_size);
379
380 if (!list->head)
381 {
382 list->head = node;
383 list->tail = node;
384 } else
385 {
386 list->head->prev= node;
387 list->head = node;
388 }
389 ++list->size;
390
391 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
392}
393
394ZyanStatus ZyanListEmplaceBack(ZyanList* list, void** item, ZyanMemberFunction constructor)
395{
396 if (!list || !item)
397 {
398 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
399 }
400
401 ZyanListNode* node;
402 ZYAN_CHECK(ZyanListAllocateNode(list, &node))do { const ZyanStatus status_047620348 = (ZyanListAllocateNode
(list, &node)); if (!(!((status_047620348) & 0x80000000u
))) { return status_047620348; } } while (0)
;
403 node->prev = list->tail;
404 node->next = ZYAN_NULL((void*)0);
405
406 *item = ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1));
407 if (constructor)
408 {
409 constructor(*item);
410 }
411
412 if (!list->head)
413 {
414 list->head = node;
415 list->tail = node;
416 } else
417 {
418 list->tail->next = node;
419 list->tail = node;
420 }
421 ++list->size;
422
423 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
424}
425
426ZyanStatus ZyanListEmplaceFront(ZyanList* list, void** item, ZyanMemberFunction constructor)
427{
428 if (!list || !item)
429 {
430 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
431 }
432
433 ZyanListNode* node;
434 ZYAN_CHECK(ZyanListAllocateNode(list, &node))do { const ZyanStatus status_047620348 = (ZyanListAllocateNode
(list, &node)); if (!(!((status_047620348) & 0x80000000u
))) { return status_047620348; } } while (0)
;
435 node->prev = ZYAN_NULL((void*)0);
436 node->next = list->head;
437
438 *item = ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1));
439 if (constructor)
440 {
441 constructor(*item);
442 }
443
444 if (!list->head)
445 {
446 list->head = node;
447 list->tail = node;
448 } else
449 {
450 list->head->prev= node;
451 list->head = node;
452 }
453 ++list->size;
454
455 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
456}
457
458/* ---------------------------------------------------------------------------------------------- */
459/* Deletion */
460/* ---------------------------------------------------------------------------------------------- */
461
462ZyanStatus ZyanListPopBack(ZyanList* list)
463{
464 if (!list)
465 {
466 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
467 }
468 if (!list->tail)
469 {
470 return ZYAN_STATUS_INVALID_OPERATION(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x05u) & 0xFFFFFu))
;
471 }
472
473 ZyanListNode* const node = list->tail;
474
475 if (list->destructor)
476 {
477 list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)));
478 }
479
480 list->tail = node->prev;
481 if (list->tail)
482 {
483 list->tail->next = ZYAN_NULL((void*)0);
484 }
485 if (list->head == node)
486 {
487 list->head = list->tail;
488 }
489 --list->size;
490
491 return ZyanListDeallocateNode(list, node);
492}
493
494ZyanStatus ZyanListPopFront(ZyanList* list)
495{
496 if (!list)
497 {
498 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
499 }
500 if (!list->head)
501 {
502 return ZYAN_STATUS_INVALID_OPERATION(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x05u) & 0xFFFFFu))
;
503 }
504
505 ZyanListNode* const node = list->head;
506
507 if (list->destructor)
508 {
509 list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)));
510 }
511
512 list->head = node->next;
513 if (list->head)
514 {
515 list->head->prev = ZYAN_NULL((void*)0);
516 }
517 if (list->tail == node)
518 {
519 list->tail = list->head;
520 }
521 --list->size;
522
523 return ZyanListDeallocateNode(list, node);
524}
525
526ZyanStatus ZyanListRemove(ZyanList* list, const ZyanListNode* node)
527{
528 ZYAN_UNUSED(list)(void)(list);
529 ZYAN_UNUSED(node)(void)(node);
530 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
531}
532
533ZyanStatus ZyanListRemoveRange(ZyanList* list, const ZyanListNode* first, const ZyanListNode* last)
534{
535 ZYAN_UNUSED(list)(void)(list);
536 ZYAN_UNUSED(first)(void)(first);
537 ZYAN_UNUSED(last)(void)(last);
538 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
539}
540
541ZyanStatus ZyanListClear(ZyanList* list)
542{
543 return ZyanListResizeEx(list, 0, ZYAN_NULL((void*)0));
544}
545
546/* ---------------------------------------------------------------------------------------------- */
547/* Searching */
548/* ---------------------------------------------------------------------------------------------- */
549
550
551
552/* ---------------------------------------------------------------------------------------------- */
553/* Memory management */
554/* ---------------------------------------------------------------------------------------------- */
555
556ZyanStatus ZyanListResize(ZyanList* list, ZyanUSize size)
557{
558 return ZyanListResizeEx(list, size, ZYAN_NULL((void*)0));
1
Calling 'ZyanListResizeEx'
559}
560
561ZyanStatus ZyanListResizeEx(ZyanList* list, ZyanUSize size, const void* initializer)
562{
563 if (!list)
2
Assuming 'list' is non-null
3
Taking false branch
564 {
565 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
566 }
567 if (size == list->size)
4
Assuming 'size' is not equal to field 'size'
5
Taking false branch
568 {
569 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
570 }
571
572 if (size == 0)
6
Assuming 'size' is not equal to 0
7
Taking false branch
573 {
574 const ZyanBool is_dynamic = (list->allocator != ZYAN_NULL((void*)0));
575 ZyanListNode* node = (is_dynamic || list->destructor) ? list->head : ZYAN_NULL((void*)0);
576 while (node)
577 {
578 if (list->destructor)
579 {
580 list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)));
581 }
582
583 ZyanListNode* const next = node->next;
584
585 if (is_dynamic)
586 {
587 ZYAN_CHECK(list->allocator->deallocate(list->allocator, node,do { const ZyanStatus status_047620348 = (list->allocator->
deallocate(list->allocator, node, sizeof(ZyanListNode) + list
->element_size, 1)); if (!(!((status_047620348) & 0x80000000u
))) { return status_047620348; } } while (0)
588 sizeof(ZyanListNode) + list->element_size, 1))do { const ZyanStatus status_047620348 = (list->allocator->
deallocate(list->allocator, node, sizeof(ZyanListNode) + list
->element_size, 1)); if (!(!((status_047620348) & 0x80000000u
))) { return status_047620348; } } while (0)
;
589 }
590
591 node = next;
592 }
593
594 list->size = 0;
595 list->head = 0;
596 list->tail = 0;
597 list->first_unused = ZYAN_NULL((void*)0);
598
599 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
600 }
601
602 if (size > list->size)
8
Assuming 'size' is <= field 'size'
9
Taking false branch
603 {
604 ZyanListNode* node;
605 for (ZyanUSize i = list->size; i < size; ++i)
606 {
607 ZYAN_CHECK(ZyanListAllocateNode(list, &node))do { const ZyanStatus status_047620348 = (ZyanListAllocateNode
(list, &node)); if (!(!((status_047620348) & 0x80000000u
))) { return status_047620348; } } while (0)
;
608 node->prev = list->tail;
609 node->next = ZYAN_NULL((void*)0);
610
611 if (initializer)
612 {
613 ZYAN_MEMCPYmemcpy(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)), initializer, list->element_size);
614 }
615
616 if (!list->head)
617 {
618 list->head = node;
619 list->tail = node;
620 } else
621 {
622 list->tail->next = node;
623 list->tail = node;
624 }
625
626 // `ZyanListAllocateNode` needs the list size
627 ++list->size;
628 }
629 } else
630 {
631 for (ZyanUSize i = size; i < list->size; ++i)
10
Assuming 'i' is < field 'size'
11
Loop condition is true. Entering loop body
20
Assuming 'i' is < field 'size'
21
Loop condition is true. Entering loop body
632 {
633 ZyanListNode* const node = list->tail;
22
'node' initialized to a null pointer value
634
635 if (list->destructor
22.1
Field 'destructor' is non-null
)
12
Assuming field 'destructor' is non-null
13
Taking true branch
23
Taking true branch
636 {
637 list->destructor(ZYCORE_LIST_GET_NODE_DATA(node)((void*)(node + 1)));
14
Value assigned to field 'prev'
24
Addition of a null pointer (from variable 'node') and a nonzero integer value results in undefined behavior
638 }
639
640 list->tail = node->prev;
15
Value assigned to field 'tail'
641 if (list->tail)
16
Assuming field 'tail' is null
17
Taking false branch
642 {
643 list->tail->next = ZYAN_NULL((void*)0);
644 }
645
646 ZYAN_CHECK(ZyanListDeallocateNode(list, node))do { const ZyanStatus status_047620348 = (ZyanListDeallocateNode
(list, node)); if (!(!((status_047620348) & 0x80000000u))
) { return status_047620348; } } while (0)
;
18
Taking false branch
19
Loop condition is false. Exiting loop
647 }
648
649 list->size = size;
650 }
651
652 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
653}
654
655/* ---------------------------------------------------------------------------------------------- */
656/* Information */
657/* ---------------------------------------------------------------------------------------------- */
658
659ZyanStatus ZyanListGetSize(const ZyanList* list, ZyanUSize* size)
660{
661 if (!list)
662 {
663 return ZYAN_STATUS_INVALID_ARGUMENT(ZyanStatus)((((1u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x04u) & 0xFFFFFu))
;
664 }
665
666 *size = list->size;
667
668 return ZYAN_STATUS_SUCCESS(ZyanStatus)((((0u) & 0x01u) << 31u) | (((0x001u) &
0x7FFu) << 20u) | ((0x00u) & 0xFFFFFu))
;
669}
670
671/* ---------------------------------------------------------------------------------------------- */
672
673/* ============================================================================================== */