From: Sami Kerola Date: Wed, 19 May 2021 19:23:48 +0000 (+0100) Subject: more: fix floating point exception core dump X-Git-Tag: v2.37~22^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ec4153cc28c718e064a1992a76a63ec7696d33a6;p=thirdparty%2Futil-linux.git more: fix floating point exception core dump Make the code avoid divided by zero. This can happen when file has content but is zero in size. Such files can be found from procfs, possibly some other pseudo-filesystems. To reproduce the issue run the following. $ more /proc/crypto ... Floating point exception (core dumped) Signed-off-by: Sami Kerola --- diff --git a/text-utils/more.c b/text-utils/more.c index b61b37a864..ee42dffb9b 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -727,7 +727,7 @@ static void output_prompt(struct more_control *ctl, char *filename) ctl->prompt_len += printf(_("--More--")); if (filename != NULL) { ctl->prompt_len += printf(_("(Next file: %s)"), filename); - } else if (!ctl->no_tty_in) { + } else if (!ctl->no_tty_in && 0 < ctl->file_size) { ctl->prompt_len += printf("(%d%%)", (int)((ctl->file_position * 100) / ctl->file_size));