IterRemainingLength
Description
Elements remaining to read in the iteration direction. Returns 0 once the iterator is past the end (forward) or past the start (reverse).
Usage example (Cross-references)
Usage examples (Cross-references)
- In
StrIter.h:268:
/// TAGS: StrIter, Length, Remaining, Alias
///
#define StrIterRemainingLength(mi) IterRemainingLength(mi)
///
- In
Access.h:85:
/// TAGS: Memory, Iter, Size
///
#define IterRemainingSize(mi) (IterRemainingLength(mi) * ALIGN_UP(sizeof(ITER_DATA_TYPE(mi)), (mi)->alignment))
///
- In
Access.h:94:
///
#define IterPos(mi) \
(IterRemainingLength(mi) ? \
(ITER_DATA_TYPE(mi) *)(((u64)(mi)->data) + \
(mi)->pos * ALIGN_UP(sizeof(ITER_DATA_TYPE(mi)), (mi)->alignment)) : \- In
Access.h:111:
///
#define IterRead(mi, out) \
(IterRemainingLength(mi) ? (*(out) = (mi)->data[(mi)->pos], (mi)->pos = (mi)->pos + (mi)->dir, true) : false)
///
- In
Io.c:827:
// a short buffer is a soft parse failure (rewind + false),
// not an abort -- this is how magic bytes are checked inline.
if (IterRemainingLength(iter) < 1 || *(const u8 *)IterPos(iter) != (u8)fc) {
*iter = start;
return false;- In
Io.c:839:
char esc = 0;
if (StrIterPeek(&fsi, &esc) && esc == '{') {
if (IterRemainingLength(iter) < 1 || *(const u8 *)IterPos(iter) != (u8)'{') {
*iter = start;
return false;- In
Io.c:870:
}
// Bounds check in iter space; pointer arithmetic stays inside the buffer.
if (fmt_info.width > IterRemainingLength(iter)) {
*iter = start;
return false;- In
Pe.c:379:
for (u32 i = 0; i < ctx->num_sections; ++i) {
if (IterRemainingLength(&c) < 40) {
LOG_ERROR("PE: section table truncated at index {}", i);
return false;- In
Pe.c:474:
continue;
}
if (IterRemainingLength(&cv_cur) < 16 + 4)
continue;
// Same proof: 16 bytes are live.
- In
DwarfInfo.c:108:
static bool parse_abbrev_table(BufIter cur, AbbrevTable *out, Allocator *alloc) {
*out = VecInitT(*out, alloc);
while (IterRemainingLength(&cur) > 0) {
u64 code;
if (!BufReadULeb128(&cur, &code)) {- In
DwarfInfo.c:346:
int depth = 0;
for (;;) {
if (IterRemainingLength(&cu_cur) == 0)
return true;- In
DwarfInfo.c:541:
bool ok = true;
while (IterRemainingLength(&info_cur) > 0) {
size unit_start_pos = IterIndex(&info_cur);- In
Tzif.c:50:
static bool tzif_read_header(BufIter *it, TzifHeader *h) {
if ((u64)IterRemainingLength(it) < TZIF_HEADER_SIZE)
return false; if (!BufReadULeb128(body, &aug_len))
return false;
if (aug_len > IterRemainingLength(body))
return false;
size aug_end_pos = IterIndex(body) + aug_len;
out->initial_instructions = IterDataAt(body, IterIndex(body));
out->initial_instructions_size = IterRemainingLength(body);
return true;
} if (!BufReadULeb128(body, &aug_len))
return false;
if (aug_len > IterRemainingLength(body))
return false;
// Must-precondition: the `aug_len > IterRemainingLength` check
out->instructions = IterDataAt(body, IterIndex(body));
out->instructions_size = IterRemainingLength(body);
return true;
} const u32 cie_id = is_debug_frame ? 0xffffffffu : 0u;
BufIter section_cur = BufIterFromMemory(section_data, section_size);
while (IterRemainingLength(§ion_cur) > 0) {
const u8 *rec_start = IterDataAt(§ion_cur, IterIndex(§ion_cur));
u32 length32 = 0; break;
}
if (length32 > IterRemainingLength(§ion_cur))
break; if (!BufReadULeb128(cur, &expr_len))
return false;
if (expr_len > IterRemainingLength(cur))
return false;
// Must-precondition: the `expr_len > IterRemainingLength`
BufIter cur = BufIterFromMemory(insns, insns_size);
bool stop_now = false;
while (IterRemainingLength(&cur) > 0) {
if (!cfi_vm_step(vm, &cur, stop_at, &stop_now))
return false;- In
MachO.c:304:
for (u32 i = 0; i < ctx->ncmds; ++i) {
u64 remaining = IterRemainingLength(&walker);
if (remaining < 8) {
LOG_ERROR("MachO: load command prefix truncated at {}", i);- In
Elf.c:424:
return;
if ((u64)IterRemainingLength(&it) < descsz)
return;- In
Dwarf.c:158:
out->std_opcode_lengths_count = out->opcode_base ? (u64)(out->opcode_base - 1) : 0;
if (IterRemainingLength(cur) < out->std_opcode_lengths_count)
return false;
out->standard_opcode_lengths = IterDataAt(cur, IterIndex(cur));- In
Dwarf.c:563:
bool ok = true;
while (IterRemainingLength(§ion_cur) > 0) {
const u8 *unit_start = IterDataAt(§ion_cur, IterIndex(§ion_cur));
u32 unit_length = 0;- In
Dwarf.c:576:
break;
}
if (4u + (u64)unit_length > IterRemainingLength(§ion_cur)) {
ok = false;
break;- In
Buf.c:106:
ok = ok && BufReadU32BE(&it, &v32) && v32 == 0x12345678;
ok = ok && BufReadU64LE(&it, &v64) && v64 == 0xFEEDFACECAFEBEEFull;
ok = ok && IterRemainingLength(&it) == 0;
BufDeinit(&b);- In
Buf.c:124:
bool ok = BufReadULeb128(&it, &uv) && uv == 624485;
ok = ok && BufReadSLeb128(&it, &sv) && sv == -123456;
ok = ok && IterRemainingLength(&it) == 0;
BufDeinit(&b);- In
Buf.c:141:
Zstr s2 = BufReadZstr(&it);
bool ok = s1 && s2 && s1[0] == 'h' && s2[0] == 'w';
ok = ok && IterRemainingLength(&it) == 0;
BufDeinit(&b);- In
Buf.c:226:
bool ok = BufReadFmt(&it, "{<2r}{>4r}{<8r}", v16, v32, v64);
ok = ok && v16 == 0x1234 && v32 == 0xDEADBEEF && v64 == 0x0102030405060708ull;
ok = ok && IterRemainingLength(&it) == 0;
BufDeinit(&b);- In
Write.c:845:
u8 ver = 0xAB;
bool rd = BufReadFmt(&it, "TZig{>1r}", ver);
ok = ok && !rd && (ver == 0xAB) && (IterRemainingLength(&it) == 5);
}- In
Deadend.c:79:
const u8 buf[2] = {1, 2};
BufIter it = {.data = buf, .length = 2, .pos = 0, .alignment = 1, .dir = 0};
(void)IterRemainingLength(&it);
return true;
}- In
Iter.c:22:
const u8 buf[3] = {1, 2, 3};
BufIter it = BufIterFromMemory(buf, 3);
if (IterRemainingLength(&it) != 3) {
return false;
}- In
Iter.c:27:
u8 v;
IterRead(&it, &v);
if (IterRemainingLength(&it) != 2) {
return false;
}- In
Iter.c:32:
IterRead(&it, &v);
IterRead(&it, &v);
return IterRemainingLength(&it) == 0;
}- In
Iter.c:38:
const u8 buf[3] = {1, 2, 3};
BufIter it = from_rev(buf, 3);
if (IterRemainingLength(&it) != 3) {
return false;
}- In
Iter.c:43:
u8 v;
IterRead(&it, &v);
if (IterRemainingLength(&it) != 2) {
return false;
}- In
Iter.c:48:
IterRead(&it, &v);
IterRead(&it, &v);
return IterRemainingLength(&it) == 0;
}- In
Iter.c:153:
return false;
}
return IterRemainingLength(&it) == 0;
}- In
Iter.c:196:
return false;
}
return IterRemainingLength(&it) == 0;
}- In
Iter.c:329:
}
// Sentinel would read as exhausted; index 0 still has one element.
return IterRemainingLength(&it) == 1;
}- In
Iter.c:367:
}
// Original returns 0 (pos not < length); mutant returns pos + 1 == 3.
return IterRemainingLength(&it) == 0;
}- In
Iter.c:418:
IterMove(&it, 1); // cursor at index 1
IterTruncate(&it, 2); // only indices 1,2 remain reachable
if (IterRemainingLength(&it) != 2) {
return false;
}- In
Iter.c:440:
IterMove(&parent, 1); // parent cursor at index 1
BufIter child = IterCarve(&parent, 2);
if (IterRemainingLength(&child) != 2 || IterIndex(&child) != 0) {
return false;
}
Last updated on