Patchwork mercurial/parsers.c: fix compiler warning

login
register
mail settings
Submitter Abhay Kadam
Date Nov. 19, 2013, 6:20 p.m.
Message ID <db74d4113cdfa6294edb.1384885207@abhay-macbook>
Download mbox | patch
Permalink /patch/3066/
State Accepted
Commit 40b7c6e4b9934c59c244f0a8b8a44258065b1174
Headers show

Comments

Abhay Kadam - Nov. 19, 2013, 6:20 p.m.
# HG changeset patch
# User Abhay Kadam <abhaykadam88@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.
Bryan O'Sullivan - Nov. 27, 2013, 5:56 a.m.
On Tue, Nov 19, 2013 at 10:20 AM, Abhay Kadam <abhaykadam88@gmail.com>wrote:

> mercurial/parsers.c: fix compiler warning
>

Applied, thanks.
Abhay Kadam - Nov. 28, 2013, 5:01 p.m.
Thanks for accepting the patch.

- Abhay

On 27-Nov-2013, at 11:26 am, Bryan O'Sullivan <bos@serpentine.com> wrote:

> 
> On Tue, Nov 19, 2013 at 10:20 AM, Abhay Kadam <abhaykadam88@gmail.com> wrote:
> mercurial/parsers.c: fix compiler warning
> 
> Applied, thanks.

Patch

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();