# HG changeset patch # User Mike Becker # Date 1755550855 -7200 # Node ID b2ba79f4cb624e363a5014f978fd0d23de33681c # Parent fe3ac6b1cf57086519b2f55872a1eb0efb502e9c also support NULL in index-based iterator generating functions diff -r fe3ac6b1cf57 -r b2ba79f4cb62 docs/Writerside/topics/list.h.md --- a/docs/Writerside/topics/list.h.md Sun Aug 17 23:10:25 2025 +0200 +++ b/docs/Writerside/topics/list.h.md Mon Aug 18 23:00:55 2025 +0200 @@ -290,7 +290,7 @@ The functions with `Mut` in are equivalently, except that they create a [mutating iterator](iterator.h.md#mutating-iterators). Removing elements via a mutating iterator will cause an invocation of the [destructor functions](collection.h.md#destructor-functions) for the removed element. -If is safe to specify an out-of-bounds index in which case an iterator is returned for which `cxIteratorValid()` returns `false`, immediately. +If is safe to specify an out-of-bounds index, or a `NULL` pointer, in which cases an iterator is returned for which `cxIteratorValid()` returns `false`, immediately. ## Reorder diff -r fe3ac6b1cf57 -r b2ba79f4cb62 src/cx/list.h --- a/src/cx/list.h Sun Aug 17 23:10:25 2025 +0200 +++ b/src/cx/list.h Mon Aug 18 23:00:55 2025 +0200 @@ -872,18 +872,18 @@ * * The returned iterator is position-aware. * - * If the index is out of range, a past-the-end iterator will be returned. + * If the index is out of range or @p list is @c NULL, a past-the-end iterator will be returned. * * @param list the list * @param index the index where the iterator shall point at * @return a new iterator */ -cx_attr_nonnull cx_attr_nodiscard static inline CxIterator cxListIteratorAt( const CxList *list, size_t index ) { + if (list == NULL) list = cxEmptyList; return list->cl->iterator(list, index, false); } @@ -892,18 +892,18 @@ * * The returned iterator is position-aware. * - * If the index is out of range, a past-the-end iterator will be returned. + * If the index is out of range or @p list is @c NULL, a past-the-end iterator will be returned. * * @param list the list * @param index the index where the iterator shall point at * @return a new iterator */ -cx_attr_nonnull cx_attr_nodiscard static inline CxIterator cxListBackwardsIteratorAt( const CxList *list, size_t index ) { + if (list == NULL) list = cxEmptyList; return list->cl->iterator(list, index, true); }