Patchwork [2,of,2] reachableroots: silence warning of implicit integer narrowing issued by clang

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 27, 2015, 2:32 p.m.
Message ID <d344ac47b3332921c24d.1440685922@mimosa>
Download mbox | patch
Permalink /patch/10296/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 27, 2015, 2:32 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1439522714 -32400
#      Fri Aug 14 12:25:14 2015 +0900
# Node ID d344ac47b3332921c24d0518ca3accb21adb3990
# Parent  941c785d0bcc1891d4df6ecc991d851d146131dd
reachableroots: silence warning of implicit integer narrowing issued by clang

Tested with CFLAGS=-Wshorten-64-to-32 CC=clang which is the default of
Mac OS X.

Because a valid revnum shouldn't exceed INT_MAX, we don't need long width for
large tovisit array.
Augie Fackler - Aug. 27, 2015, 3:21 p.m.
On Thu, Aug 27, 2015 at 11:32:02PM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1439522714 -32400
> #      Fri Aug 14 12:25:14 2015 +0900
> # Node ID d344ac47b3332921c24d0518ca3accb21adb3990
> # Parent  941c785d0bcc1891d4df6ecc991d851d146131dd
> reachableroots: silence warning of implicit integer narrowing issued by clang

Queued these, thanks.

>
> Tested with CFLAGS=-Wshorten-64-to-32 CC=clang which is the default of
> Mac OS X.
>
> Because a valid revnum shouldn't exceed INT_MAX, we don't need long width for
> large tovisit array.

mpm, please double-check this logic - I'm pretty sure this is all correct.

>
> diff --git a/mercurial/parsers.c b/mercurial/parsers.c
> --- a/mercurial/parsers.c
> +++ b/mercurial/parsers.c
> @@ -1187,7 +1187,7 @@ static PyObject *reachableroots2(indexOb
>                       goto bail;
>               }
>               if (!(revstates[revnum + 1] & RS_SEEN)) {
> -			tovisit[lentovisit++] = revnum;
> +			tovisit[lentovisit++] = (int)revnum;
>                       revstates[revnum + 1] |= RS_SEEN;
>               }
>       }
> @@ -1228,7 +1228,7 @@ static PyObject *reachableroots2(indexOb
>       /* Find all the nodes in between the roots we found and the heads
>        * and add them to the reachable set */
>       if (includepath == 1) {
> -		int minidx = minroot;
> +		long minidx = minroot;
>               if (minidx < 0)
>                       minidx = 0;
>               for (i = minidx; i < len; i++) {
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1187,7 +1187,7 @@  static PyObject *reachableroots2(indexOb
 			goto bail;
 		}
 		if (!(revstates[revnum + 1] & RS_SEEN)) {
-			tovisit[lentovisit++] = revnum;
+			tovisit[lentovisit++] = (int)revnum;
 			revstates[revnum + 1] |= RS_SEEN;
 		}
 	}
@@ -1228,7 +1228,7 @@  static PyObject *reachableroots2(indexOb
 	/* Find all the nodes in between the roots we found and the heads
 	 * and add them to the reachable set */
 	if (includepath == 1) {
-		int minidx = minroot;
+		long minidx = minroot;
 		if (minidx < 0)
 			minidx = 0;
 		for (i = minidx; i < len; i++) {