IterTruncate
Description
Bound the iterator so only n further elements are reachable from the current position. Caps length at pos + n; subsequent IterRead/IterPeekAt/IterMove calls treat the new tail as past-the-end. Use when a structural field (e.g. a Mach-O cmdsize) tells you the in-memory record ends earlier than the underlying buffer.
Success
mi->length is set to mi->pos + n; subsequent reads see the new end. The macro evaluates to void.
Failure
Macro cannot fail. Caller is responsible for not passing an n that extends past the original buffer (no validation is performed – the cap can only shrink reach, but raising length past the real allocation would over-read on the next access).
Usage example (Cross-references)
Usage examples (Cross-references)
- In
MachO.c:301:
// inside `walker`.
IterMustMove(&walker, MH_HEADER_64_SIZE);
IterTruncate(&walker, ctx->sizeofcmds);
for (u32 i = 0; i < ctx->ncmds; ++i) {- In
MachO.c:375:
// `symoff <= tab_end <= BufLength` and the move stays in-bounds.
IterMustMove(&tab, ctx->symoff);
IterTruncate(&tab, (u64)ctx->nsyms * NLIST64_SIZE);
for (u32 i = 0; i < ctx->nsyms; ++i) {
u32 n_strx;- In
Iter.c:359:
BufIter it = from_rev(buf, 3); // dir == -1, pos == 2, length == 3
// length := pos + 0 == 2, so now pos (2) == length (2).
IterTruncate(&it, 0);
if (IterIndex(&it) != 2) {
return false;- In
Iter.c:417:
BufIter it = BufIterFromMemory(buf, 5);
IterMove(&it, 1); // cursor at index 1
IterTruncate(&it, 2); // only indices 1,2 remain reachable
if (IterRemainingLength(&it) != 2) {
return false;
Last updated on