From 20123b25ee51e9b122676a30d45c21a506bf1461 Mon Sep 17 00:00:00 2001 From: Robert Wing Date: Thu, 20 May 2021 12:53:52 -0800 Subject: [PATCH] fsck_ffs(8): fix divide by zero when debug messages are enabled Only print buffer cache debug message when a cache lookup has been done. When running `fsck_ffs -d` on a gjournal'ed filesystem, it's possible that totalreads is greater than zero when no cache lookup has been done - causing a divide by zero. This commit fixes the following error: Floating point exception (core dumped) Reviewed by: mckusick Differential Revision: https://reviews.freebsd.org/D30370 --- sbin/fsck_ffs/fsutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sbin/fsck_ffs/fsutil.c b/sbin/fsck_ffs/fsutil.c index b13ba4c54bde..db22ee5b20cf 100644 --- a/sbin/fsck_ffs/fsutil.c +++ b/sbin/fsck_ffs/fsutil.c @@ -576,7 +576,7 @@ ckfini(int markclean) rerun = 1; } } - if (debug && totalreads > 0) + if (debug && cachelookups > 0) printf("cache with %d buffers missed %d of %d (%d%%)\n", numbufs, cachereads, cachelookups, (int)(cachereads * 100 / cachelookups));