{
trace_assert(lt);
- for (Slot *p = lt->slots_end; p != lt->slots; --p) {
+ for (Slot *p = lt->slots_end - 1; p >= lt->slots; --p) {
if (p->res) {
p->dtor(p->res);
}
static inline void *lt_push(Lt *lt, void *res, Dtor dtor)
{
trace_assert(lt);
-
- if ((size_t)(lt->slots_end - lt->slots) >= lt->capacity) {
+ size_t size = (size_t)(lt->slots_end - lt->slots);
+ if (size >= lt->capacity) {
if (lt->capacity == 0) {
lt->capacity = LT_INITIAL_CAPACITY;
lt->slots = calloc(LT_INITIAL_CAPACITY, sizeof(Slot));
} else {
lt->capacity *= 2;
lt->slots = realloc(lt->slots, lt->capacity * sizeof(Slot));
- lt->slots_end = lt->slots;
+ lt->slots_end = lt->slots + size;
}
}