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
Io.c:850:
}
// Bounds check in iter space; pointer arithmetic stays inside the buffer.
if (fmt_info.width > IterRemainingLength(iter)) {
*iter = start;
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
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
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); 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;
}
BufIter section_cur = BufIterFromMemory(section_data, eh->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
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
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
Iter.c:18:
const u8 buf[3] = {1, 2, 3};
BufIter it = BufIterFromMemory(buf, 3);
if (IterRemainingLength(&it) != 3) {
return false;
}- In
Iter.c:23:
u8 v;
IterRead(&it, &v);
if (IterRemainingLength(&it) != 2) {
return false;
}- In
Iter.c:28:
IterRead(&it, &v);
IterRead(&it, &v);
return IterRemainingLength(&it) == 0;
}- In
Iter.c:34:
const u8 buf[3] = {1, 2, 3};
BufIter it = from_rev(buf, 3);
if (IterRemainingLength(&it) != 3) {
return false;
}- In
Iter.c:39:
u8 v;
IterRead(&it, &v);
if (IterRemainingLength(&it) != 2) {
return false;
}- In
Iter.c:44:
IterRead(&it, &v);
IterRead(&it, &v);
return IterRemainingLength(&it) == 0;
}- In
Iter.c:149:
return false;
}
return IterRemainingLength(&it) == 0;
}- In
Iter.c:192:
return false;
}
return IterRemainingLength(&it) == 0;
}- In
StrIter.h:194:
/// 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)
///
Last updated on