From 278b70e25a37bae191066c4e08f96fd8624f31e4 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 17 Jun 2019 13:27:36 +0200 Subject: [PATCH] com_stats(): Avoid division by zero. If no epigrams are defined yet, the arguments to printf() contain a division by zero which results in output like: average number of epigrams per file -nan average number of tags per epigram. -nan average number of tag recurrence... -nan This is not a wrong per se, but it seems to be safer to special case this and print zero. --- tfortune.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tfortune.c b/tfortune.c index 751334d..ec4c323 100644 --- a/tfortune.c +++ b/tfortune.c @@ -895,11 +895,11 @@ static int com_stats(void) printf("number of tags..................... %5lu\n", num_tags); printf("number of unique tags.............. %5u\n", num_unique_tags); printf("average number of epigrams per file %8.02f\n", - (float)num_epis / num_epi_files); - printf("average number of tags per epigram. %8.02f\n", - (float)num_tags / num_epis); - printf("average number of tag recurrence... %8.02f\n", - (float)num_tags / num_unique_tags); + num_epi_files > 0? (float)num_epis / num_epi_files : 0); + printf("average number of tags per epigram. %8.02f\n", num_epis > 0? + (float)num_tags / num_epis : 0); + printf("average number of tag recurrence... %8.02f\n", num_unique_tags > 0? + (float)num_tags / num_unique_tags : 0); if (verbose) { printf("\nlinear hashing statistics:\n%s\n", lh_stats); free(lh_stats); -- 2.39.5