After removing an entry, the next entry will be at the same offset as
the entry we just removed. Also the total length will have changed.
Update the length when we remove an entry, and advance the offset only
when we don't.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
uint8_t *start = odhcp6c_get_state(state, &len);
for (struct odhcp6c_entry *c = (struct odhcp6c_entry*)start;
(uint8_t*)c < &start[len] && &c->auxtarget[c->auxlen] <= &start[len];
- c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen])) {
+ ) {
if (c->t1 < elapsed)
c->t1 = 0;
else if (c->t1 != UINT32_MAX)
else if (c->valid != UINT32_MAX)
c->valid -= elapsed;
- if (!c->valid)
+ if (!c->valid) {
odhcp6c_remove_state(state, ((uint8_t*)c) - start, sizeof(*c) + c->auxlen);
+ start = odhcp6c_get_state(state, &len);
+ } else {
+ c = (struct odhcp6c_entry*)(&c->auxtarget[c->auxlen]);
+ }
}
}