aboutsummaryrefslogtreecommitdiff
path: root/src/gdbmtool.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gdbmtool.c')
-rw-r--r--src/gdbmtool.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/gdbmtool.c b/src/gdbmtool.c
index c522ad0..18d0e10 100644
--- a/src/gdbmtool.c
+++ b/src/gdbmtool.c
@@ -222,39 +222,49 @@ _gdbm_avail_list_size (GDBM_FILE dbf, size_t min_size)
else
terror ("read: %s (%s)",
gdbm_strerror (rc), strerror (errno));
break;
}
- lines += av_stk->count;
- if (lines > min_size)
- break;
+ if (gdbm_avail_block_valid_p (av_stk))
+ {
+ lines += av_stk->count;
+ if (lines > min_size)
+ break;
+ }
temp = av_stk->next_block;
}
free (av_stk);
return lines;
}
+static void
+av_table_display (avail_elem *av_table, int count, FILE *fp)
+{
+ int i;
+
+ for (i = 0; i < count; i++)
+ {
+ fprintf (fp, " %15d %10lu \n",
+ av_table[i].av_size, (unsigned long) av_table[i].av_adr);
+ }
+}
+
void
_gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf)
{
int temp;
int size;
avail_block *av_stk;
int rc;
/* Print the the header avail block. */
fprintf (fp, _("\nheader block\nsize = %d\ncount = %d\n"),
dbf->header->avail.size, dbf->header->avail.count);
- for (temp = 0; temp < dbf->header->avail.count; temp++)
- {
- fprintf (fp, " %15d %10lu \n",
- dbf->header->avail.av_table[temp].av_size,
- (unsigned long) dbf->header->avail.av_table[temp].av_adr);
- }
+ av_table_display (dbf->header->avail.av_table, dbf->header->avail.count, fp);
/* Initialize the variables for a pass throught the avail stack. */
temp = dbf->header->avail.next_block;
size = (((dbf->header->avail.size * sizeof (avail_elem)) >> 1)
+ sizeof (avail_block));
av_stk = emalloc (size);
@@ -277,17 +287,16 @@ _gdbm_print_avail_list (FILE *fp, GDBM_FILE dbf)
break;
}
/* Print the block! */
fprintf (fp, _("\nblock = %d\nsize = %d\ncount = %d\n"), temp,
av_stk->size, av_stk->count);
- for (temp = 0; temp < av_stk->count; temp++)
- {
- fprintf (fp, " %15d %10lu \n", av_stk->av_table[temp].av_size,
- (unsigned long) av_stk->av_table[temp].av_adr);
- }
+ if (gdbm_avail_block_valid_p (av_stk))
+ av_table_display (av_stk->av_table, av_stk->count, fp);
+ else
+ terror (_("invalid avail_block"));
temp = av_stk->next_block;
}
free (av_stk);
}
void

Return to:

Send suggestions and report system problems to the System administrator.