Patchwork mercurial/parsers.c: fix compiler warning

login
register
mail settings
Submitter Abhay Kadam
Date Nov. 17, 2013, 6:38 a.m.
Message ID <9eb232aa2fe76ed1b76f.1384670307@abhay-macbook>
Download mbox | patch
Permalink /patch/3058/
State Superseded
Commit 40b7c6e4b9934c59c244f0a8b8a44258065b1174
Headers show

Comments

Abhay Kadam - Nov. 17, 2013, 6:38 a.m.
# HG changeset patch
# User Abhay Kadam <abhaykadam88@gmail.com>
# Date 1384669735 -19800
#      Sun Nov 17 11:58:55 2013 +0530
# Node ID 9eb232aa2fe76ed1b76f6bec012a2d155322769a
# Parent  aa80446aacc3b1574211649cd8f190250b6b04b3
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. 18, 2013, 6:11 p.m.
On Sat, Nov 16, 2013 at 10:38 PM, Abhay Kadam <abhaykadam88@gmail.com>wrote:

> mercurial/parsers.c: fix compiler warning
>

Patch looks fine, but the indentation is busted.

Patch

diff -r aa80446aacc3 -r 9eb232aa2fe7 mercurial/parsers.c
--- a/mercurial/parsers.c	Wed Nov 06 12:53:39 2013 -0500
+++ b/mercurial/parsers.c	Sun Nov 17 11:58:55 2013 +0530
@@ -927,8 +927,12 @@ 
 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();