Patchwork [4,of,4,warning-cleanup] parsers: avoid comparing Py_ssize_t (aka long) with unsigned long

login
register
mail settings
Submitter Augie Fackler
Date Aug. 21, 2015, 6:36 p.m.
Message ID <a8abb7badebc5d2fd181.1440182172@augie-macbookair2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/10247/
State Accepted
Headers show

Comments

Augie Fackler - Aug. 21, 2015, 6:36 p.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1440182108 14400
#      Fri Aug 21 14:35:08 2015 -0400
# Node ID a8abb7badebc5d2fd18189f83b3140aa7af2ac5c
# Parent  c94fce4d889c4f83b6d62bd8a2d4550aa0fb91f0
parsers: avoid comparing Py_ssize_t (aka long) with unsigned long

Detected with
make local CFLAGS='-Wall -Wextra -Wno-missing-field-initializers -Wno-unused-parameter' CC=clang

As of this change, that command no longer emits compiler errors.
Matt Mackall - Aug. 26, 2015, 10:16 p.m.
On Fri, 2015-08-21 at 14:36 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1440182108 14400
> #      Fri Aug 21 14:35:08 2015 -0400
> # Node ID a8abb7badebc5d2fd18189f83b3140aa7af2ac5c
> # Parent  c94fce4d889c4f83b6d62bd8a2d4550aa0fb91f0
> parsers: avoid comparing Py_ssize_t (aka long) with unsigned long
> 

I've queued 2-4 here, thanks.

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1576,7 +1576,7 @@  static int nt_insert(indexObject *self, 
 static int nt_init(indexObject *self)
 {
 	if (self->nt == NULL) {
-		if (self->raw_length > INT_MAX / sizeof(nodetree)) {
+		if (self->raw_length > (Py_ssize_t) (INT_MAX / sizeof(nodetree))) {
 			PyErr_SetString(PyExc_ValueError, "overflow in nt_init");
 			return -1;
 		}