Patchwork [V2] parsers.c: avoid implicit conversion loses integer precision warnings

login
register
mail settings
Submitter André Sintzoff
Date Aug. 18, 2015, 3:14 p.m.
Message ID <3de6766f291354f2f4e2.1439910842@zibeline.local>
Download mbox | patch
Permalink /patch/10230/
State Rejected
Delegated to: Augie Fackler
Headers show

Comments

André Sintzoff - Aug. 18, 2015, 3:14 p.m.
# HG changeset patch
# User André Sintzoff <andre.sintzoff@gmail.com>
# Date 1439902654 -7200
#      Tue Aug 18 14:57:34 2015 +0200
# Node ID 3de6766f291354f2f4e206dc5be9ca231f1eef4c
# Parent  9e7d805925c87cfa0ca30819e8273ac37fd77a62
parsers.c: avoid implicit conversion loses integer precision warnings

These warnings are raised by Apple LLVM version 6.1.0 (clang-602.0.53)
(based on LLVM 3.6.0svn) and were introduced in ff89383a97db
Augie Fackler - Aug. 18, 2015, 6:03 p.m.
On Tue, Aug 18, 2015 at 05:14:02PM +0200, André Sintzoff wrote:
> # HG changeset patch
> # User André Sintzoff <andre.sintzoff@gmail.com>
> # Date 1439902654 -7200
> #      Tue Aug 18 14:57:34 2015 +0200
> # Node ID 3de6766f291354f2f4e206dc5be9ca231f1eef4c
> # Parent  9e7d805925c87cfa0ca30819e8273ac37fd77a62
> parsers.c: avoid implicit conversion loses integer precision warnings
>
> These warnings are raised by Apple LLVM version 6.1.0 (clang-602.0.53)
> (based on LLVM 3.6.0svn) and were introduced in ff89383a97db
>
> diff -r 9e7d805925c8 -r 3de6766f2913 mercurial/parsers.c
> --- a/mercurial/parsers.c	Fri Aug 14 12:36:41 2015 +0900
> +++ b/mercurial/parsers.c	Tue Aug 18 14:57:34 2015 +0200
> @@ -1121,11 +1121,11 @@
>
>       PyObject *val;
>       Py_ssize_t len = index_length(self) - 1;
> -	long revnum;
> +	int revnum;
>       Py_ssize_t k;
>       Py_ssize_t i;
>       int r;
> -	int minidx;
> +	long minidx;
>       int parents[2];
>
>       /* Internal data structure:
> @@ -1166,7 +1166,7 @@
>       /* Populate tovisit with all the heads */
>       numheads = PyList_GET_SIZE(heads);
>       for (i = 0; i < numheads; i++) {
> -		revnum = PyInt_AsLong(PyList_GET_ITEM(heads, i));
> +		revnum = (int)PyInt_AsLong(PyList_GET_ITEM(heads, i));

Do we know that this list entry will fit in an int and not a long? I'm
slightly skeptical of this change.

>               if (revnum == -1 && PyErr_Occurred())
>                       goto bail;
>               if (revnum + 1 < 0 || revnum + 1 >= len + 1) {
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
Yuya Nishihara - Aug. 19, 2015, 12:42 p.m.
On Tue, 18 Aug 2015 14:03:29 -0400, Augie Fackler wrote:
> On Tue, Aug 18, 2015 at 05:14:02PM +0200, André Sintzoff wrote:
> > # HG changeset patch
> > # User André Sintzoff <andre.sintzoff@gmail.com>
> > # Date 1439902654 -7200
> > #      Tue Aug 18 14:57:34 2015 +0200
> > # Node ID 3de6766f291354f2f4e206dc5be9ca231f1eef4c
> > # Parent  9e7d805925c87cfa0ca30819e8273ac37fd77a62
> > parsers.c: avoid implicit conversion loses integer precision warnings
> >
> > These warnings are raised by Apple LLVM version 6.1.0 (clang-602.0.53)
> > (based on LLVM 3.6.0svn) and were introduced in ff89383a97db
> >
> > diff -r 9e7d805925c8 -r 3de6766f2913 mercurial/parsers.c
> > --- a/mercurial/parsers.c	Fri Aug 14 12:36:41 2015 +0900
> > +++ b/mercurial/parsers.c	Tue Aug 18 14:57:34 2015 +0200
> > @@ -1121,11 +1121,11 @@
> >
> >       PyObject *val;
> >       Py_ssize_t len = index_length(self) - 1;
> > -	long revnum;
> > +	int revnum;
> >       Py_ssize_t k;
> >       Py_ssize_t i;
> >       int r;
> > -	int minidx;
> > +	long minidx;
> >       int parents[2];
> >
> >       /* Internal data structure:
> > @@ -1166,7 +1166,7 @@
> >       /* Populate tovisit with all the heads */
> >       numheads = PyList_GET_SIZE(heads);
> >       for (i = 0; i < numheads; i++) {
> > -		revnum = PyInt_AsLong(PyList_GET_ITEM(heads, i));
> > +		revnum = (int)PyInt_AsLong(PyList_GET_ITEM(heads, i));
> 
> Do we know that this list entry will fit in an int and not a long? I'm
> slightly skeptical of this change.

Narrowing revnum won't cause serious problem here, but I think it's safer
to keep revnum as long until it is verified as a good revision number.

Patch

diff -r 9e7d805925c8 -r 3de6766f2913 mercurial/parsers.c
--- a/mercurial/parsers.c	Fri Aug 14 12:36:41 2015 +0900
+++ b/mercurial/parsers.c	Tue Aug 18 14:57:34 2015 +0200
@@ -1121,11 +1121,11 @@ 
 
 	PyObject *val;
 	Py_ssize_t len = index_length(self) - 1;
-	long revnum;
+	int revnum;
 	Py_ssize_t k;
 	Py_ssize_t i;
 	int r;
-	int minidx;
+	long minidx;
 	int parents[2];
 
 	/* Internal data structure:
@@ -1166,7 +1166,7 @@ 
 	/* Populate tovisit with all the heads */
 	numheads = PyList_GET_SIZE(heads);
 	for (i = 0; i < numheads; i++) {
-		revnum = PyInt_AsLong(PyList_GET_ITEM(heads, i));
+		revnum = (int)PyInt_AsLong(PyList_GET_ITEM(heads, i));
 		if (revnum == -1 && PyErr_Occurred())
 			goto bail;
 		if (revnum + 1 < 0 || revnum + 1 >= len + 1) {