[PATCH] mercurial/parsers.c: fix compiler warning

Abhay Kadam abhaykadam88 at gmail.com
Tue Nov 19 12:20:07 CST 2013


# HG changeset patch
# User Abhay Kadam <abhaykadam88 at gmail.com>
# Date 1384885151 -19800
#      Tue Nov 19 23:49:11 2013 +0530
# Node ID db74d4113cdfa6294edbbf1b90833f17823137c1
# Parent  6d4fda48b4e3710cfc2161f676adb46c424079d3
mercurial/parsers.c: fix compiler warning

When try to compile on x64 OS X, I get this warning:

mercurial/parsers.c:931:27: warning: implicit conversion loses integer precision
: 'long' to 'int' [-Wshorten-64-to-32]
                        ? 4 : self->raw_length / 2;

The patch verifies if value of self->raw_length falls bellow INT_MAX; if not,
it raises the ValueError exception.

If value of self->raw_length is greater than 4, it's casted to int type, to
eliminate the warning.

diff -r 6d4fda48b4e3 -r db74d4113cdf mercurial/parsers.c
--- a/mercurial/parsers.c	Tue Nov 19 11:29:56 2013 -0500
+++ b/mercurial/parsers.c	Tue Nov 19 23:49:11 2013 +0530
@@ -927,8 +927,13 @@
 static int nt_init(indexObject *self)
 {
 	if (self->nt == NULL) {
+		if (self->raw_length > INT_MAX) {
+			PyErr_SetString(PyExc_ValueError, "overflow in nt_init");
+			return -1;
+		}
 		self->ntcapacity = self->raw_length < 4
-			? 4 : self->raw_length / 2;
+			? 4 : (int)self->raw_length / 2;
+
 		self->nt = calloc(self->ntcapacity, sizeof(nodetree));
 		if (self->nt == NULL) {
 			PyErr_NoMemory();


More information about the Mercurial-devel mailing list