Skip to content

IterLength

Description

Total length (in elements) of the region the iterator covers.

Usage example (Cross-references)

Usage examples (Cross-references)
    
    static bool decode_segment_64(MachoContext *ctx, BufIter *cmd) {
        u64 cmdsize = IterLength(cmd);
        if (cmdsize < SEG64_CMD_SIZE_MIN) {
            LOG_ERROR("MachO: LC_SEGMENT_64 truncated");
        // SECT64_SIZE bytes.
        for (u32 i = 0; i < seg.nsects; ++i) {
            if (IterIndex(cmd) + SECT64_SIZE > IterLength(cmd)) {
                LOG_ERROR("MachO: section table overruns LC_SEGMENT_64");
                return false;
    
    static bool decode_symtab(MachoContext *ctx, BufIter *cmd) {
        if (IterLength(cmd) < SYMTAB_CMD_SIZE) {
            LOG_ERROR("MachO: LC_SYMTAB truncated");
            return false;
    
    static bool decode_uuid(MachoContext *ctx, BufIter *cmd) {
        if (IterLength(cmd) < UUID_CMD_SIZE) {
            LOG_ERROR("MachO: LC_UUID truncated");
            return false;
    // start of the line number program body.
    static bool skip_line_program_tables(BufIter *cur) {
        while (IterIndex(cur) < IterLength(cur) && *IterDataAt(cur, IterIndex(cur)) != 0) {
            if (!BufReadZstr(cur))
                return false;
        // Must-precondition: the surrounding `IterIndex < IterLength` test
        // proves there is at least one more byte to consume (the NUL).
        if (IterIndex(cur) < IterLength(cur))
            IterMustNext(cur); // empty terminator
            IterMustNext(cur); // empty terminator
    
        while (IterIndex(cur) < IterLength(cur) && *IterDataAt(cur, IterIndex(cur)) != 0) {
            if (!BufReadZstr(cur))
                return false;
        // Must-precondition: same `IterIndex < IterLength` proof as the
        // include_directories terminator above.
        if (IterIndex(cur) < IterLength(cur))
            IterMustNext(cur); // empty terminator
        return true;
    static bool collect_cu_strings(BufIter cur, Str *pool, CuStrings *cs) {
        // include_directories
        while (IterIndex(&cur) < IterLength(&cur) && *IterDataAt(&cur, IterIndex(&cur)) != 0) {
            Zstr dir = BufReadZstr(&cur);
            if (!dir)
        // Must-precondition: `IterIndex < IterLength` proves there is a
        // terminator byte left to consume.
        if (IterIndex(&cur) < IterLength(&cur))
            IterMustNext(&cur); // empty terminator
    
        // file_names
        while (IterIndex(&cur) < IterLength(&cur) && *IterDataAt(&cur, IterIndex(&cur)) != 0) {
            Zstr name = BufReadZstr(&cur);
            if (!name)
            }
            size unit_end_pos = unit_start_pos + 4u + unit_length;
            if (unit_end_pos > IterLength(&info_cur) || unit_end_pos < unit_start_pos) {
                LOG_ERROR("DWARF info: CU overruns section");
                ok = false;
        u64       name_len  = 0;
        u64       label_idx = 0;
        while (cur < IterLength(it)) {
            u8 b = *IterDataAt(it, cur);
            if (b == 0) {
            if ((b & 0xC0u) == 0xC0u) {
                // Compression pointer: 14-bit offset.
                if (cur + 2 > IterLength(it)) {
                    return false;
                }
            }
            u64 label_len = (u64)b;
            if (cur + 1 + label_len > IterLength(it)) {
                return false;
            }
        rec->ttl    = ttl;
    
        if (IterIndex(it) + (u64)rdlength > IterLength(it)) {
            return false;
        }
            // Verify the trailing path is NUL-terminated inside the record.
            const u8 *path_start = IterDataAt(&cv_cur, IterIndex(&cv_cur));
            const u8 *region_end = IterDataAt(&cv_cur, IterLength(&cv_cur));
            bool      terminated = false;
            for (const u8 *p = path_start; p < region_end; ++p) {
    /// TAGS: StrIter, Length, Alias
    ///
    #define StrIterLength(mi) IterLength(mi)
    
    ///
    /// TAGS: Memory, Size, Iter
    ///
    #define IterSize(mi) (IterLength(mi) * ALIGN_UP(sizeof(ITER_DATA_TYPE(mi)), (mi)->alignment))
    
    ///
Last updated on