git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] Avoid a floating point exception in merge-recursive.
Date: Sun, 14 Jan 2007 03:11:23 -0500	[thread overview]
Message-ID: <20070114081123.GA19566@spearce.org> (raw)

If we have no files selected for processing yet but we try to
produce a status output this would cause a division by zero error
when computing the percent done.  Last time I talked to a user,
crashing a program over performing an undefined operation isn't
very nice.  So instead lets set the percentage done to 0.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---

 This is on top of the merge-recursive series I just sent.
 You may already have it fixed in your tree, or maybe not.

 merge-recursive.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index c4e21bc..2a89461 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -182,7 +182,7 @@ static void setup_progress_signal(void)
 
 static void display_progress()
 {
-	unsigned percent = merged_cnt * 100 / total_cnt;
+	unsigned percent = total_cnt ? merged_cnt * 100 / total_cnt : 0;
 	if (progress_update || percent != last_percent) {
 		fprintf(stderr, "%4u%% (%u/%u) done\r",
 			percent, merged_cnt, total_cnt);
-- 
1.5.0.rc1.g4494

                 reply	other threads:[~2007-01-14  8:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070114081123.GA19566@spearce.org \
    --to=spearce@spearce.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).