unsigned int *num_buckets)
{
struct free_zone_header zhdr;
- tdb_off_t off;
+ tdb_off_t off, end;
tdb_len_t len;
unsigned int hdrlen;
tdb_len_t unc = 0;
hdrlen = sizeof(zhdr)
+ (BUCKETS_FOR_ZONE(zhdr.zone_bits) + 1) * sizeof(tdb_off_t);
- for (off = zone_off + hdrlen;
- off < zone_off + (1ULL << zhdr.zone_bits);
- off += len) {
+
+ end = zone_off + (1ULL << zhdr.zone_bits);
+ if (end > tdb->map_size)
+ end = tdb->map_size;
+
+ for (off = zone_off + hdrlen; off < end; off += len) {
union {
struct tdb_used_record u;
struct tdb_free_record f;
p = tdb_get(tdb, off, &pad, sizeof(pad));
if (!p)
return TDB_OFF_ERR;
- if (frec_magic(&p->f) == TDB_FREE_MAGIC) {
+ if (rec_magic(&p->u) != TDB_MAGIC) {
len = p->f.data_len;
tally_add(free, len);
bucketlen[size_to_bucket(frec_zone_bits(&p->f), len)]++;