Skip to content

Commit 1f067ea

Browse files
committed
Revert "Rework am_onesize_iterate_over_allocated()"
This reverts commit 27e3c5b.
1 parent 994e189 commit 1f067ea

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

libs/onesize/onesize.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,20 @@ void am_onesize_iterate_over_allocated_unsafe(
137137
if (num < 0) {
138138
num = hnd->ntotal;
139139
}
140+
int iterated = 0;
140141
num = AM_MIN(num, hnd->ntotal);
141142

142-
for (int i = 0; i < num; ++i) {
143+
for (int i = 0; (i < hnd->ntotal) && (iterated < num); ++i) {
143144
AM_ASSERT(AM_ALIGNOF_PTR(ptr) >= AM_ALIGNOF_SLIST_ITEM);
144145
struct am_slist_item *item = AM_CAST(struct am_slist_item *, ptr);
145146
if (am_slist_owns(&hnd->fl, item)) {
146147
continue; /* the item is free */
147148
}
148149

149-
cb(ctx, i, (char *)item, hnd->block_size);
150+
cb(ctx, iterated, (char *)item, hnd->block_size);
150151

151152
ptr += hnd->block_size;
153+
++iterated;
152154
}
153155
}
154156

0 commit comments

Comments
 (0)