git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Avoid a floating point exception in merge-recursive.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 14, 2007, 08:11 UTC
Message-ID
<20070114081123.GA19566@spearce.org>

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
Message 1 of 1 in “Avoid a floating point exception in merge-recursive.”
  1. 1/2 Avoid a floating point exception in merge-recursive.Shawn O. Pearce, Jan 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.