File hg-mpatch-fix05.patch of Package mercurial.11266

# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1525366460 14400
# Node ID b8b253aec9538b2614295f6ba4ecefe335ad8bf5
# Parent  1ec4cb8cbc87004ffbeeb1b5d98acef04c38d59a
mpatch: introduce a safesub() helper as well

Same reason as safeadd().

---
 mercurial/mpatch.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

--- a/mercurial/mpatch.c
+++ b/mercurial/mpatch.c
@@ -102,6 +102,17 @@ static inline bool safeadd(int src, int
 	return true;
 }
 
+/* subtract src from dest and store result in dest */
+static inline bool safesub(int src, int *dest)
+{
+	if (((src > 0) && (*dest < INT_MIN + src)) ||
+	    ((src < 0) && (*dest > INT_MAX + src))) {
+		return false;
+	}
+	*dest -= src;
+	return true;
+}
+
 /* move hunks in source that are less cut to dest, compensating
    for changes in offset. the last hunk may be split if necessary.
 */
openSUSE Build Service is sponsored by