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

[PATCH 1/2] diffcore-break: don't divide by zero

From
John Keeping <john@keeping.me.uk>
Date
Apr 2, 2013, 19:50 UTC
Message-ID
<a2b6c61371ac6ff1e180c6600e57499ff94b2fd2.1364931627.git.john@keeping.me.uk>
In-Reply-To
<cover.1364931627.git.john@keeping.me.uk>

When the source file is empty, the calculation of the merge score results in a division by zero. Since the merge score is initialized to zero, it makes sense to just leave it as it is if the source size is zero. This means that we still use the extent of damage metric to decide whether to break the filepair.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 diffcore-break.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/diffcore-break.c b/diffcore-break.c
index 44f8678..37d8d05 100644
--- a/diffcore-break.c
+++ b/diffcore-break.c
@@ -90,7 +90,8 @@ static int should_break(struct diff_filespec *src,
 	 * merge the surviving pair together if the score is
 	 * less than the minimum, after rename/copy runs.
 	 */
-	*merge_score_p = (int)(src_removed * MAX_SCORE / src->size);
+	if (src->size)
+		*merge_score_p = (int)(src_removed * MAX_SCORE / src->size);
 	if (*merge_score_p > break_score)
 		return 1;
 
-- 
1.8.2.540.gf023cfe
Previous: John KeepingNext: Junio C Hamano
Message 2 of 9 in “Fixes for undefined behaviour”
  1. 0/2 Fixes for undefined behaviourJohn Keeping, Apr 2, 2013
  2. 1/2 diffcore-break: don't divide by zeroJohn Keeping, Apr 2, 2013
  3. Junio C HamanoApr 2, 2013
  4. John KeepingApr 2, 2013
  5. Junio C HamanoApr 2, 2013
  6. diffcore-break: don't divide by zeroJohn Keeping, Apr 3, 2013
  7. 2/2 bisect: avoid signed integer overflowJohn Keeping, Apr 2, 2013
  8. Junio C HamanoApr 2, 2013
  9. John KeepingApr 3, 2013

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.