[PATCH] xdiff: fix trivial build warnings on Windows

Matt Harbison mharbison72 at gmail.com
Sun Mar 4 21:45:28 UTC 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1520197662 18000
#      Sun Mar 04 16:07:42 2018 -0500
# Node ID c4a6b599a46f93070f5492c9e68566e6be570d2f
# Parent  1f9bbd1d6b8ae4f7ea5d9f4310269a3b0242e7b0
xdiff: fix trivial build warnings on Windows

These are mostly size_t to int/long conversions that are obviously safe, along
with a signed/unsigned comparison.  I don't have clang, so I tried following the
existing whitespace convention in each module.

diff --git a/mercurial/thirdparty/xdiff/xemit.c b/mercurial/thirdparty/xdiff/xemit.c
--- a/mercurial/thirdparty/xdiff/xemit.c
+++ b/mercurial/thirdparty/xdiff/xemit.c
@@ -31,7 +31,7 @@
 
 
 static int xdl_emit_record(xdfile_t *xdf, long ri, char const *pre, xdemitcb_t *ecb) {
-	long size, psize = strlen(pre);
+	long size, psize = (long)strlen(pre);
 	char const *rec;
 
 	size = xdl_get_rec(xdf, ri, &rec);
@@ -81,7 +81,8 @@
 		} else if (distance < max_ignorable && xch->ignore) {
 			ignored += xch->chg2;
 		} else if (lxch != xchp &&
-			   xch->i1 + ignored - (lxch->i1 + lxch->chg1) > max_common) {
+			   xch->i1 + ignored - (lxch->i1 + lxch->chg1)
+				> (unsigned long)max_common) {
 			break;
 		} else if (!xch->ignore) {
 			lxch = xch;
diff --git a/mercurial/thirdparty/xdiff/xmerge.c b/mercurial/thirdparty/xdiff/xmerge.c
--- a/mercurial/thirdparty/xdiff/xmerge.c
+++ b/mercurial/thirdparty/xdiff/xmerge.c
@@ -199,9 +199,9 @@
 			      int size, int i, int style,
 			      xdmerge_t *m, char *dest, int marker_size)
 {
-	int marker1_size = (name1 ? strlen(name1) + 1 : 0);
-	int marker2_size = (name2 ? strlen(name2) + 1 : 0);
-	int marker3_size = (name3 ? strlen(name3) + 1 : 0);
+	int marker1_size = (name1 ? (int)strlen(name1) + 1 : 0);
+	int marker2_size = (name2 ? (int)strlen(name2) + 1 : 0);
+	int marker3_size = (name3 ? (int)strlen(name3) + 1 : 0);
 	int needs_cr = is_cr_needed(xe1, xe2, m);
 
 	if (marker_size <= 0)
diff --git a/mercurial/thirdparty/xdiff/xutils.c b/mercurial/thirdparty/xdiff/xutils.c
--- a/mercurial/thirdparty/xdiff/xutils.c
+++ b/mercurial/thirdparty/xdiff/xutils.c
@@ -51,7 +51,7 @@
 	mb[1].size = size;
 	if (size > 0 && rec[size - 1] != '\n') {
 		mb[2].ptr = (char *) "\n\\ No newline at end of file\n";
-		mb[2].size = strlen(mb[2].ptr);
+		mb[2].size = (long) strlen(mb[2].ptr);
 		i++;
 	}
 	if (ecb->outf(ecb->priv, mb, i) < 0) {
@@ -341,7 +341,7 @@
 		*str++ = '0';
 	*str = '\0';
 
-	return str - out;
+	return (int) (str - out);
 }
 
 int xdl_emit_hunk_hdr(long s1, long c1, long s2, long c2,


More information about the Mercurial-devel mailing list