Skip to content

VecPtrAt

Description

Pointer to the element at idx. Use this rather than indexing data directly so element alignment is respected.

Parameters

Name Direction Description
v in Vector to query.
idx in Index in [0, length).

Usage example (Cross-references)

Usage examples (Cross-references)
        for (u64 i = 0; i < n_specs; ++i) {
            left_col[i] = StrInit(self->alloc);
            left_w[i]   = spec_format_left(VecPtrAt(&self->specs, i), &left_col[i]);
            if (left_w[i] > max_w)
                max_w = left_w[i];
        bool printed_options_header    = false;
        for (u64 i = 0; i < n_specs; ++i) {
            ArgSpec *sp = VecPtrAt(&self->specs, i);
            if (sp->role != ARG_ROLE_POSITIONAL)
                continue;
    
        for (u64 i = 0; i < n_specs; ++i) {
            ArgSpec *sp = VecPtrAt(&self->specs, i);
            if (sp->role == ARG_ROLE_POSITIONAL)
                continue;
    static const DebugFreedEntry *debug_freed_find(const DebugAllocator *dbg, void *ptr) {
        for (u32 i = 0; i < VecLen(&dbg->freed); i++) {
            if (VecPtrAt(&dbg->freed, i)->ptr == ptr)
                return VecPtrAt(&dbg->freed, i);
        }
        for (u32 i = 0; i < VecLen(&dbg->freed); i++) {
            if (VecPtrAt(&dbg->freed, i)->ptr == ptr)
                return VecPtrAt(&dbg->freed, i);
        }
        return NULL;
    
    static GenericGraphSlot *graph_slot_ptr_raw(GenericGraph *graph, u32 index) {
        return VecPtrAt(&graph->slots, index);
    }
    
    static const GenericGraphSlot *graph_slot_ptr_const_raw(const GenericGraph *graph, u32 index) {
        return VecPtrAt((GraphSlots *)&graph->slots, index);
    }
        for (idx = 0; idx < VecLen(&graph->pending_edge_removals); idx++) {
            const GraphPendingEdgeRemoval *pending =
                VecPtrAt((GraphPendingEdgeRemovals *)&graph->pending_edge_removals, idx);
            if ((pending->from == from) && (pending->to == to)) {
                return idx;
    
        for (slot_index = 0; slot_index < VecLen(&graph->slots); slot_index++) {
            const GenericGraphSlot *slot    = VecPtrAt((GraphSlots *)&graph->slots, slot_index);
            GraphNodeId             self_id = graph_make_node_id((u32)slot_index, slot->generation);
            u64                     neighbor_i;
            }
    
            if (graph_slot_is_occupied(VecPtrAt((GraphSlots *)&graph->slots, index))) {
                LOG_FATAL("Graph free index points to an occupied slot");
            }
        for (free_index_i = 0; free_index_i < VecLen(&graph->pending_edge_removals); free_index_i++) {
            const GraphPendingEdgeRemoval *pending =
                VecPtrAt((GraphPendingEdgeRemovals *)&graph->pending_edge_removals, free_index_i);
            const GraphNeighbors *neighbors;
    
        for (slot_index = 0; slot_index < VecLen(&graph->slots); slot_index++) {
            GenericGraphSlot *slot = VecPtrAt(&graph->slots, slot_index);
            if (graph_slot_is_occupied(slot)) {
                graph_release_slot(graph, slot, item_size);
        explicit_edge_removal_count = VecLen(&graph->pending_edge_removals);
        for (edge_idx = 0; edge_idx < VecLen(&graph->pending_edge_removals); edge_idx++) {
            GraphPendingEdgeRemoval *pending = VecPtrAt(&graph->pending_edge_removals, edge_idx);
            (void)graph_remove_edge_now(graph, pending->from, pending->to);
        }
    
        for (slot_index = 0; slot_index < VecLen(&graph->slots); slot_index++) {
            GenericGraphSlot *slot = VecPtrAt(&graph->slots, slot_index);
            if (graph_slot_is_occupied(slot) && graph_slot_is_marked(slot)) {
                GraphNodeId marked_id = graph_make_node_id((u32)slot_index, slot->generation);
    
        for (slot_index = 0; slot_index < VecLen(&graph->slots); slot_index++) {
            GenericGraphSlot *slot = VecPtrAt(&graph->slots, slot_index);
            if (graph_slot_is_occupied(slot) && !graph_slot_is_marked(slot)) {
                GraphNodeId live_id = graph_make_node_id((u32)slot_index, slot->generation);
    
        for (slot_index = 0; slot_index < VecLen(&graph->slots); slot_index++) {
            GenericGraphSlot *slot = VecPtrAt(&graph->slots, slot_index);
            if (graph_slot_is_occupied(slot) && graph_slot_is_marked(slot)) {
                if (VecLen(&slot->out_neighbors) || VecLen(&slot->in_neighbors)) {
        while (iter->slot_index < VecLen(&iter->graph->slots)) {
            u32               index  = (u32)iter->slot_index;
            GenericGraphSlot *slot   = VecPtrAt(&iter->graph->slots, iter->slot_index);
            iter->slot_index        += 1;
    static PdbCacheEntry *cache_find_or_open(PdbCache *self, Zstr module_path) {
        for (size i = 0; i < VecLen(&self->entries); ++i) {
            PdbCacheEntry *e = VecPtrAt(&self->entries, i);
            if (StrBegin(&e->module_path) && ZstrCompare(StrBegin(&e->module_path), module_path) == 0) {
                return e;
            return NULL;
        }
        return VecPtrAt(&self->entries, VecLen(&self->entries) - 1);
    }
            return;
        for (size i = 0; i < VecLen(&self->entries); ++i) {
            PdbCacheEntry *e = VecPtrAt(&self->entries, i);
            if (e->pdb_open)
                PdbDeinit(&e->pdb);
    static ResolverCacheEntry *resolver_cache_find_or_open(SymbolResolver *self, Zstr path, u64 load_base) {
        for (u64 i = 0; i < VecLen(&self->cache); ++i) {
            ResolverCacheEntry *e = VecPtrAt(&self->cache, i);
            if (e->path == path) {
                return e;
            return NULL;
        }
        return VecPtrAt(&self->cache, VecLen(&self->cache) - 1);
    }
            return;
        for (u64 i = 0; i < VecLen(&self->cache); ++i) {
            ResolverCacheEntry *e = VecPtrAt(&self->cache, i);
    #if FEATURE_PARSER_DWARF
            if (e->dwarf_built && e->dwarf_ok) {
            return NULL;
        for (u64 i = 0; i < VecLen(&self->entries); ++i) {
            const ProcMapEntry *e = VecPtrAt(&self->entries, i);
            if (addr >= e->start && addr < e->end) {
                return e;
        bool trail_sep = (path_len > 0 && path[path_len - 1] == '/');
        for (size i = 0; i < VecLen(&dc); ++i) {
            DirEntry *e        = VecPtrAt(&dc, i);
            Zstr      entry_nm = StrBegin(&e->name);
            if (ZstrCompare(entry_nm, ".") == 0 || ZstrCompare(entry_nm, "..") == 0) {
    static MachoCacheEntry *cache_find_or_create(MachoCache *self, Zstr module_path) {
        for (size i = 0; i < VecLen(&self->entries); ++i) {
            MachoCacheEntry *e = VecPtrAt(&self->entries, i);
            if (StrBegin(&e->module_path) && ZstrCompare(StrBegin(&e->module_path), module_path) == 0) {
                return e;
            return NULL;
        }
        return VecPtrAt(&self->entries, VecLen(&self->entries) - 1);
    }
            return;
        for (size i = 0; i < VecLen(&self->entries); ++i) {
            MachoCacheEntry *e = VecPtrAt(&self->entries, i);
            if (e->fns_built && e->fns_ok)
                DwarfFunctionsDeinit(&e->fns);
            return NULL;
        for (size i = 0; i < VecLen(&self->sections); ++i) {
            const MachoSection *s = VecPtrAt(&self->sections, i);
            if (ZstrCompare(s->segment, segment) == 0 && ZstrCompare(s->section, section) == 0) {
                return s;
    
        for (size i = 0; i < VecLen(&self->symbols); ++i) {
            const MachoSymbol *s = VecPtrAt(&self->symbols, i);
            if (s->type & N_STAB_MASK)
                continue; // any high bit set => STAB (debug) entry
            return false;
        }
        const ElfSection *strtab = VecPtrAt(&self->sections, strtab_idx);
        if (!elf_range_ok(self, strtab->offset, strtab->size)) {
            LOG_ERROR("Elf: strtab out of range");
    
        for (u64 i = 0; i < VecLen(&self->sections); ++i) {
            const ElfSection *s = VecPtrAt(&self->sections, i);
            if (s->type == ELF_SECTION_TYPE_SYMTAB) {
                symtab = s;
        const ElfSymbol *best = NULL;
        for (u64 i = 0; i < VecLen(syms); ++i) {
            const ElfSymbol *s = VecPtrAt(syms, i);
            if (s->size == 0) {
                // Some symbols (e.g. labels) have zero size — only match
            return NULL;
        for (u64 i = 0; i < VecLen(&self->sections); ++i) {
            const ElfSection *s = VecPtrAt(&self->sections, i);
            if (s->name && ZstrCompare(s->name, name) == 0) {
                return s;
                u64 fo                           = VecAt(&pending_file_offsets, i);
                u64 dofs                         = VecAt(&pending_dir_offsets, i);
                VecPtrAt(&out->entries, i)->file = fo ? (Zstr)(StrBegin(&out->string_pool) + fo) : NULL;
                VecPtrAt(&out->entries, i)->dir  = dofs ? (Zstr)(StrBegin(&out->string_pool) + dofs) : NULL;
            }
                u64 dofs                         = VecAt(&pending_dir_offsets, i);
                VecPtrAt(&out->entries, i)->file = fo ? (Zstr)(StrBegin(&out->string_pool) + fo) : NULL;
                VecPtrAt(&out->entries, i)->dir  = dofs ? (Zstr)(StrBegin(&out->string_pool) + dofs) : NULL;
            }
        }
        const DwarfLineEntry *seq_open = NULL;
        for (u64 i = 0; i < VecLen(&self->entries); ++i) {
            const DwarfLineEntry *e = VecPtrAt(&self->entries, i);
            if (e->end_sequence) {
                // Sequence ends at this row's address (exclusive upper).
    static void abbrev_table_deinit(AbbrevTable *t) {
        for (size i = 0; i < VecLen(t); ++i) {
            VecDeinit(&VecPtrAt(t, i)->attrs);
        }
        VecDeinit(t);
    static const AbbrevEntry *abbrev_table_find(const AbbrevTable *t, u64 code) {
        for (size i = 0; i < VecLen(t); ++i) {
            if (VecPtrAt(t, i)->code == code)
                return VecPtrAt(t, i);
        }
        for (size i = 0; i < VecLen(t); ++i) {
            if (VecPtrAt(t, i)->code == code)
                return VecPtrAt(t, i);
        }
        return NULL;
    
            for (size ai = 0; ai < VecLen(&e->attrs); ++ai) {
                const AbbrevAttr *a = VecPtrAt(&e->attrs, ai);
                AttrVal           v;
                if (!read_form(&cu_cur, a->form, addr_size, &v))
            // has stopped growing.
            for (size i = 0; i < VecLen(&pending); ++i) {
                const PendingFn *pf = VecPtrAt(&pending, i);
                DwarfFunction    f  = {
                        .low_pc  = pf->low_pc,
        while (lo < hi) {
            size mid = lo + (hi - lo) / 2;
            if (VecPtrAt(&self->entries, mid)->low_pc <= vaddr)
                lo = mid + 1;
            else
        if (lo == 0)
            return NULL;
        const DwarfFunction *e = VecPtrAt(&self->entries, lo - 1);
        if (vaddr >= e->low_pc && vaddr < e->high_pc)
            return e;
        // sizes by next-rva diff.
        for (size i = 0; i < VecLen(&pending); ++i) {
            const PendingPub *pp = VecPtrAt(&pending, i);
            PdbFunction       f  = {
                       .rva  = pp->rva,
                // order. If next.rva < f.rva (impossible today), leave
                // size = 0 rather than wrap.
                u32 next_rva = VecPtrAt(&pending, i + 1)->rva;
                f.size       = next_rva >= f.rva ? next_rva - f.rva : 0;
            }
        while (lo < hi) {
            size mid = lo + (hi - lo) / 2;
            if (((const PdbFunction *)VecPtrAt(&self->functions, mid))->rva <= rva)
                lo = mid + 1;
            else
        if (lo == 0)
            return NULL;
        const PdbFunction *f = VecPtrAt(&self->functions, lo - 1);
        // size == 0 means "until next entry"; we already accept that case.
        // Widen to u64 to avoid u32 wrap: rva and size are both u32, so a
            return NULL;
        for (u64 i = 0; i < VecLen(&self->cies); ++i) {
            if (VecPtrAt(&self->cies, i)->offset == cie_offset) {
                return VecPtrAt(&self->cies, i);
            }
        for (u64 i = 0; i < VecLen(&self->cies); ++i) {
            if (VecPtrAt(&self->cies, i)->offset == cie_offset) {
                return VecPtrAt(&self->cies, i);
            }
        }
        // Linear scan -- fine up to a few thousand FDEs.
        for (u64 i = 0; i < VecLen(&self->fdes); ++i) {
            const DwarfFde *f = VecPtrAt(&self->fdes, i);
            if (vaddr >= f->pc_begin && vaddr < f->pc_begin + f->pc_range) {
                return f;
            return NULL;
        for (size i = 0; i < VecLen(&self->sections); ++i) {
            const PeSection *s = VecPtrAt(&self->sections, i);
            if (ZstrCompare(s->name, name) == 0) {
                return s;
            return false;
        for (size i = 0; i < VecLen(&self->sections); ++i) {
            const PeSection *s = VecPtrAt(&self->sections, i);
            // Compute the section end in u64; u32 + u32 can wrap.
            u64 vstart = (u64)s->virtual_address;
                if (VecLen(vec) > 0 && *offset + 4 <= data_size) {
                    size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
                    char **ptr   = VecPtrAt(vec, index);
                    (void)ptr; // Use the result to avoid warnings
                }
                if (VecLen(vec) > 0 && *offset + 4 <= data_size) {
                    size_t index = extract_u32(data, offset, data_size) % VecLen(vec);
                    Str   *ptr   = VecPtrAt(vec, index);
                    (void)ptr; // Use the result to avoid warnings
                }
                uint16_t idx = extract_u16(data, offset, data_size);
                if (idx < VecLen(vec)) {
                    volatile i32 *ptr = VecPtrAt(vec, idx);
                    volatile i32  val = *ptr;
                    (void)val;
        if (strings_match) {
            for (size i = 0; i < VecLen(&original_strings); i++) {
                if (StrLen(VecPtrAt(&original_strings, i)) != StrLen(VecPtrAt(&parsed_strings, i)) ||
                    (StrLen(VecPtrAt(&original_strings, i)) &&
                     StrCmp(VecPtrAt(&original_strings, i), VecPtrAt(&parsed_strings, i)) != 0)) {
            for (size i = 0; i < VecLen(&original_strings); i++) {
                if (StrLen(VecPtrAt(&original_strings, i)) != StrLen(VecPtrAt(&parsed_strings, i)) ||
                    (StrLen(VecPtrAt(&original_strings, i)) &&
                     StrCmp(VecPtrAt(&original_strings, i), VecPtrAt(&parsed_strings, i)) != 0)) {
                    strings_match = false;
                if (StrLen(VecPtrAt(&original_strings, i)) != StrLen(VecPtrAt(&parsed_strings, i)) ||
                    (StrLen(VecPtrAt(&original_strings, i)) &&
                     StrCmp(VecPtrAt(&original_strings, i), VecPtrAt(&parsed_strings, i)) != 0)) {
                    strings_match = false;
                    break;
        bool result = (VecLen(&split) == 3);
        if (VecLen(&split) >= 3) {
            result = result && (ZstrCompare(StrBegin(VecPtrAt(&split, 0)), "Hello") == 0);
            result = result && (ZstrCompare(StrBegin(VecPtrAt(&split, 1)), "World") == 0);
            result = result && (ZstrCompare(StrBegin(VecPtrAt(&split, 2)), "Test") == 0);
        if (VecLen(&split) >= 3) {
            result = result && (ZstrCompare(StrBegin(VecPtrAt(&split, 0)), "Hello") == 0);
            result = result && (ZstrCompare(StrBegin(VecPtrAt(&split, 1)), "World") == 0);
            result = result && (ZstrCompare(StrBegin(VecPtrAt(&split, 2)), "Test") == 0);
        }
            result = result && (ZstrCompare(StrBegin(VecPtrAt(&split, 0)), "Hello") == 0);
            result = result && (ZstrCompare(StrBegin(VecPtrAt(&split, 1)), "World") == 0);
            result = result && (ZstrCompare(StrBegin(VecPtrAt(&split, 2)), "Test") == 0);
        }
            // (the base-pointer of an Iter range is the Iter contract --
            // direct read is the documented usage for view types).
            StrIter *iter1       = VecPtrAt(&iters, 0);
            char     buffer1[10] = {0};
            MemCopy(buffer1, iter1->data, StrIterLength(iter1));
            result = result && (ZstrCompare(buffer1, "Hello") == 0);
    
            StrIter *iter2       = VecPtrAt(&iters, 1);
            char     buffer2[10] = {0};
            MemCopy(buffer2, iter2->data, StrIterLength(iter2));
            result = result && (ZstrCompare(buffer2, "World") == 0);
    
            StrIter *iter3       = VecPtrAt(&iters, 2);
            char     buffer3[10] = {0};
            MemCopy(buffer3, iter3->data, StrIterLength(iter3));
        ok = ok && m.has_uuid && MemCompare(m.uuid, kUuid, 16) == 0;
        ok = ok && VecLen(&m.segments) == 1;
        ok = ok && ZstrCompare(VecPtrAt(&m.segments, 0)->name, "__TEXT") == 0;
        ok = ok && VecLen(&m.sections) == 1;
        ok = ok && ZstrCompare(VecPtrAt(&m.sections, 0)->section, "__text") == 0;
        ok = ok && ZstrCompare(VecPtrAt(&m.segments, 0)->name, "__TEXT") == 0;
        ok = ok && VecLen(&m.sections) == 1;
        ok = ok && ZstrCompare(VecPtrAt(&m.sections, 0)->section, "__text") == 0;
        ok = ok && ZstrCompare(VecPtrAt(&m.sections, 0)->segment, "__TEXT") == 0;
        ok = ok && VecLen(&m.symbols) == 1;
        ok = ok && VecLen(&m.sections) == 1;
        ok = ok && ZstrCompare(VecPtrAt(&m.sections, 0)->section, "__text") == 0;
        ok = ok && ZstrCompare(VecPtrAt(&m.sections, 0)->segment, "__TEXT") == 0;
        ok = ok && VecLen(&m.symbols) == 1;
        ok = ok && VecPtrAt(&m.symbols, 0)->name && ZstrCompare(VecPtrAt(&m.symbols, 0)->name, "my_function") == 0;
        ok = ok && ZstrCompare(VecPtrAt(&m.sections, 0)->segment, "__TEXT") == 0;
        ok = ok && VecLen(&m.symbols) == 1;
        ok = ok && VecPtrAt(&m.symbols, 0)->name && ZstrCompare(VecPtrAt(&m.symbols, 0)->name, "my_function") == 0;
        ok = ok && VecPtrAt(&m.symbols, 0)->value == 0x100000010ull;
        ok = ok && VecLen(&m.symbols) == 1;
        ok = ok && VecPtrAt(&m.symbols, 0)->name && ZstrCompare(VecPtrAt(&m.symbols, 0)->name, "my_function") == 0;
        ok = ok && VecPtrAt(&m.symbols, 0)->value == 0x100000010ull;
    
        MachoDeinit(&m);
        bool ok = false;
        for (u64 i = 0; i < VecLen(&elf.symbols); ++i) {
            const ElfSymbol *s = VecPtrAt(&elf.symbols, i);
            if (s->type == ELF_SYMBOL_TYPE_FUNC && s->size > 0 && s->name && s->name[0] != '\0') {
                ok = true;
        bool     got = DnsResolve(&r, "203.0.113.7:9999", SOCKET_KIND_TCP, &out);
    
        bool ok = got && VecLen(&out) == 1 && VecPtrAt(&out, 0)->family == SOCKET_FAMILY_INET;
        if (ok) {
            Str s = SocketAddrFormat(VecPtrAt(&out, 0), a);
        bool ok = got && VecLen(&out) == 1 && VecPtrAt(&out, 0)->family == SOCKET_FAMILY_INET;
        if (ok) {
            Str s = SocketAddrFormat(VecPtrAt(&out, 0), a);
            ok    = (StrLen(&s) > 0) && ZstrCompare(StrBegin(&s), "203.0.113.7:9999") == 0;
            StrDeinit(&s);
        bool     got = DnsResolve(&r, "[::1]:443", SOCKET_KIND_TCP, &out);
    
        bool ok = got && VecLen(&out) == 1 && VecPtrAt(&out, 0)->family == SOCKET_FAMILY_INET6;
        if (ok) {
            Str s = SocketAddrFormat(VecPtrAt(&out, 0), a);
        bool ok = got && VecLen(&out) == 1 && VecPtrAt(&out, 0)->family == SOCKET_FAMILY_INET6;
        if (ok) {
            Str s = SocketAddrFormat(VecPtrAt(&out, 0), a);
            // SocketAddrFormat emits the bracketed form for IPv6.
            ok = (StrLen(&s) > 0) && ZstrCompare(StrBegin(&s), "[::1]:443") == 0;
        // `DebugFreedEntry` structs with no public accessor; reach in to
        // confirm each entry carries the ptr + both traces.
        ok = ok && (VecPtrAt(&dbg.freed, 0)->ptr == p1) && (VecPtrAt(&dbg.freed, 0)->requested_size == 16);
        ok = ok && (VecPtrAt(&dbg.freed, 0)->alloc_trace_n > 0) && (VecPtrAt(&dbg.freed, 0)->free_trace_n > 0);
        ok = ok && (VecPtrAt(&dbg.freed, 2)->ptr == p3) && (VecPtrAt(&dbg.freed, 2)->requested_size == 64);
        // confirm each entry carries the ptr + both traces.
        ok = ok && (VecPtrAt(&dbg.freed, 0)->ptr == p1) && (VecPtrAt(&dbg.freed, 0)->requested_size == 16);
        ok = ok && (VecPtrAt(&dbg.freed, 0)->alloc_trace_n > 0) && (VecPtrAt(&dbg.freed, 0)->free_trace_n > 0);
        ok = ok && (VecPtrAt(&dbg.freed, 2)->ptr == p3) && (VecPtrAt(&dbg.freed, 2)->requested_size == 64);
        ok = ok && (VecPtrAt(&dbg.freed, 0)->ptr == p1) && (VecPtrAt(&dbg.freed, 0)->requested_size == 16);
        ok = ok && (VecPtrAt(&dbg.freed, 0)->alloc_trace_n > 0) && (VecPtrAt(&dbg.freed, 0)->free_trace_n > 0);
        ok = ok && (VecPtrAt(&dbg.freed, 2)->ptr == p3) && (VecPtrAt(&dbg.freed, 2)->requested_size == 64);
    
        DebugAllocatorDeinit(&dbg);
        BitVecPush(&source, true);
    
        BitVec *p0 = VecPtrAt(&patterns, 0);
        BitVec *p1 = VecPtrAt(&patterns, 1);
        BitVec *p2 = VecPtrAt(&patterns, 2);
    
        BitVec *p0 = VecPtrAt(&patterns, 0);
        BitVec *p1 = VecPtrAt(&patterns, 1);
        BitVec *p2 = VecPtrAt(&patterns, 2);
        BitVec *p0 = VecPtrAt(&patterns, 0);
        BitVec *p1 = VecPtrAt(&patterns, 1);
        BitVec *p2 = VecPtrAt(&patterns, 2);
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        BitVecPush(&source, true);
    
        BitVec *p0 = VecPtrAt(&patterns, 0);
        BitVec *p1 = VecPtrAt(&patterns, 1);
        BitVec *p2 = VecPtrAt(&patterns, 2);
    
        BitVec *p0 = VecPtrAt(&patterns, 0);
        BitVec *p1 = VecPtrAt(&patterns, 1);
        BitVec *p2 = VecPtrAt(&patterns, 2);
        BitVec *p0 = VecPtrAt(&patterns, 0);
        BitVec *p1 = VecPtrAt(&patterns, 1);
        BitVec *p2 = VecPtrAt(&patterns, 2);
    
        *p0 = BitVecInit(ALLOCATOR_OF(&alloc));
        bool any_exec = false;
        for (u64 i = 0; i < VecLen(&maps.entries); ++i) {
            if (VecPtrAt(&maps.entries, i)->perms & PROC_MAP_PERM_EXEC) {
                any_exec = true;
                break;
            // `graph.slots` is the typed `Vec(GraphSlot(int))`, so iterate via
            // the runtime-shared layout to avoid an anonymous-struct annotation.
            GenericGraphSlot *slot = (GenericGraphSlot *)VecPtrAt(&GENERIC_GRAPH(&graph)->slots, slot_index);
            result                 = result && (slot->data == NULL);
            result                 = result && (slot->visit_count == 0);
        }
    
        result = result && (VecPtrAt(&graph.slots, GraphNodeIdIndex(first_id))->generation == (first_generation + 1));
        result = result && (VecPtrAt(&graph.slots, GraphNodeIdIndex(second_id))->generation == (second_generation + 1));
        result = result && (VecPtrAt(&graph.slots, GraphNodeIdIndex(third_id))->generation == (third_generation + 1));
    
        result = result && (VecPtrAt(&graph.slots, GraphNodeIdIndex(first_id))->generation == (first_generation + 1));
        result = result && (VecPtrAt(&graph.slots, GraphNodeIdIndex(second_id))->generation == (second_generation + 1));
        result = result && (VecPtrAt(&graph.slots, GraphNodeIdIndex(third_id))->generation == (third_generation + 1));
        result = result && (VecPtrAt(&graph.slots, GraphNodeIdIndex(first_id))->generation == (first_generation + 1));
        result = result && (VecPtrAt(&graph.slots, GraphNodeIdIndex(second_id))->generation == (second_generation + 1));
        result = result && (VecPtrAt(&graph.slots, GraphNodeIdIndex(third_id))->generation == (third_generation + 1));
    
        GraphDeinit(&graph);
        result            = result && VecLen(&runs) == 5;
        if (result) {
            result = result && VecPtrAt(&runs, 0)->length == 3 && VecPtrAt(&runs, 0)->value == true;
            result = result && VecPtrAt(&runs, 1)->length == 2 && VecPtrAt(&runs, 1)->value == false;
            result = result && VecPtrAt(&runs, 2)->length == 1 && VecPtrAt(&runs, 2)->value == true;
        if (result) {
            result = result && VecPtrAt(&runs, 0)->length == 3 && VecPtrAt(&runs, 0)->value == true;
            result = result && VecPtrAt(&runs, 1)->length == 2 && VecPtrAt(&runs, 1)->value == false;
            result = result && VecPtrAt(&runs, 2)->length == 1 && VecPtrAt(&runs, 2)->value == true;
            result = result && VecPtrAt(&runs, 3)->length == 1 && VecPtrAt(&runs, 3)->value == false;
            result = result && VecPtrAt(&runs, 0)->length == 3 && VecPtrAt(&runs, 0)->value == true;
            result = result && VecPtrAt(&runs, 1)->length == 2 && VecPtrAt(&runs, 1)->value == false;
            result = result && VecPtrAt(&runs, 2)->length == 1 && VecPtrAt(&runs, 2)->value == true;
            result = result && VecPtrAt(&runs, 3)->length == 1 && VecPtrAt(&runs, 3)->value == false;
            result = result && VecPtrAt(&runs, 4)->length == 1 && VecPtrAt(&runs, 4)->value == true;
            result = result && VecPtrAt(&runs, 1)->length == 2 && VecPtrAt(&runs, 1)->value == false;
            result = result && VecPtrAt(&runs, 2)->length == 1 && VecPtrAt(&runs, 2)->value == true;
            result = result && VecPtrAt(&runs, 3)->length == 1 && VecPtrAt(&runs, 3)->value == false;
            result = result && VecPtrAt(&runs, 4)->length == 1 && VecPtrAt(&runs, 4)->value == true;
        }
            result = result && VecPtrAt(&runs, 2)->length == 1 && VecPtrAt(&runs, 2)->value == true;
            result = result && VecPtrAt(&runs, 3)->length == 1 && VecPtrAt(&runs, 3)->value == false;
            result = result && VecPtrAt(&runs, 4)->length == 1 && VecPtrAt(&runs, 4)->value == true;
        }
    // Test VecPtrAt function
    bool test_vec_ptr_at(void) {
        WriteFmt("Testing VecPtrAt\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // Get pointers to elements
        int *ptr0 = VecPtrAt(&vec, 0);
        int *ptr1 = VecPtrAt(&vec, 1);
        int *ptr2 = VecPtrAt(&vec, 2);
        // Get pointers to elements
        int *ptr0 = VecPtrAt(&vec, 0);
        int *ptr1 = VecPtrAt(&vec, 1);
        int *ptr2 = VecPtrAt(&vec, 2);
        int *ptr0 = VecPtrAt(&vec, 0);
        int *ptr1 = VecPtrAt(&vec, 1);
        int *ptr2 = VecPtrAt(&vec, 2);
    
        // Check values through pointers
        ok = VecLen(&pdb.functions) == 1;
        if (ok) {
            const PdbFunction *f = VecPtrAt(&pdb.functions, 0);
            ok                   = ok && f->rva == 0x1100 && f->name && ZstrCompare(f->name, "my_function") == 0;
        }
    
        if (match) {
            DnsRecord *r0 = VecPtrAt(&resp.answers, 0);
            match         = r0->type == DNS_TYPE_A && r0->ttl == 300 && r0->ipv4[0] == 93 && r0->ipv4[1] == 184 &&
                    r0->ipv4[2] == 216 && r0->ipv4[3] == 34 && StrLen(&r0->name) > 0 &&
        }
        if (match) {
            DnsRecord *r1 = VecPtrAt(&resp.answers, 1);
            match = r1->type == DNS_TYPE_AAAA && r1->ipv6[0] == 0x26 && r1->ipv6[1] == 0x06 && r1->ipv6[14] == 0x19 &&
                    r1->ipv6[15] == 0x46;
        bool        match = ok && VecLen(&resp.answers) == 1;
        if (match) {
            DnsRecord *r = VecPtrAt(&resp.answers, 0);
            match        = r->type == DNS_TYPE_CNAME && StrLen(&r->target) > 0 &&
                    ZstrCompare(StrBegin(&r->target), "example.com") == 0;
        WriteFmt("Testing BitVecPrefixMatch(NULL, patterns, 1) - should fatal\n");
        BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        BitVecPush(VecPtrAt(&vp, 0), true);
        BitVecPrefixMatch(NULL, &vp);
        VecDeinit(&vp);
        WriteFmt("Testing BitVecSuffixMatch(NULL, patterns, 1) - should fatal\n");
        BitVecs vp = VecInitWithDeepCopy(NULL, BitVecDeinit, ALLOCATOR_OF(&alloc));
        BitVecPush(VecPtrAt(&vp, 0), true);
        BitVecSuffixMatch(NULL, &vp);
        VecDeinit(&vp);
        ok = pe.machine == PE_MACHINE_X86_64 && pe.is_pe32_plus && pe.image_base == 0x140000000ull;
        ok = ok && VecLen(&pe.sections) == 1;
        ok = ok && ZstrCompare(VecPtrAt(&pe.sections, 0)->name, ".debug") == 0;
        ok = ok && VecPtrAt(&pe.sections, 0)->virtual_address == SECTION_VA;
        ok = ok && pe.codeview.present;
        ok = ok && VecLen(&pe.sections) == 1;
        ok = ok && ZstrCompare(VecPtrAt(&pe.sections, 0)->name, ".debug") == 0;
        ok = ok && VecPtrAt(&pe.sections, 0)->virtual_address == SECTION_VA;
        ok = ok && pe.codeview.present;
        ok = ok && pe.codeview.age == 0x2a;
            if ((ValidateVec(UNPL(pv)), 1) && UNPL(pv)->length > 0)                                                        \
                for (u64 idx = 0, UNPL(d) = 1; UNPL(d); UNPL(d)--)                                                         \
                    for (VEC_DATATYPE(UNPL(pv)) *var = NULL; idx < UNPL(pv)->length && (var = VecPtrAt(UNPL(pv), idx), 1); \
                         idx++)
                for (u64 idx = UNPL(pv)->length; idx-- > 0 && idx < UNPL(pv)->length;)                                     \
                    for (u8 UNPL(run_once) = 1; UNPL(run_once); UNPL(run_once) = 0)                                        \
                        for (VEC_DATATYPE(UNPL(pv)) *var = VecPtrAt(UNPL(pv), idx); UNPL(run_once); UNPL(run_once) = 0)
    
    ///
                     idx >= UNPL(s) && idx < UNPL(e) && idx < UNPL(pv)->length && UNPL(s) <= UNPL(e);                      \
                     ++idx, UNPL(d) = 1)                                                                                   \
                    for (VEC_DATATYPE(UNPL(pv)) *var = VecPtrAt(UNPL(pv), idx); UNPL(d); UNPL(d) = 0)
    
    ///
    /// TAGS: Str, Access, Index, Pointer
    ///
    #define StrCharPtrAt(str, idx) VecPtrAt(str, idx)
    
    ///
Last updated on