Patchwork [6,of,6,v2] parsers: avoid signed/unsigned comparison mismatch

login
register
mail settings
Submitter Henrik Stuart
Date Sept. 9, 2014, 5:51 p.m.
Message ID <86b438ac398f552a397f.1410285102@yggdrasil>
Download mbox | patch
Permalink /patch/5743/
State Accepted
Headers show

Comments

Henrik Stuart - Sept. 9, 2014, 5:51 p.m.
# HG changeset patch
# User Henrik Stuart <hg@hstuart.dk>
# Date 1410202664 -7200
#      Mon Sep 08 20:57:44 2014 +0200
# Node ID 86b438ac398f552a397f03b5f1b87352611db5ef
# Parent  8bfb3cef896c160faec2659c4758fc9d3d28b1c4
parsers: avoid signed/unsigned comparison mismatch

Based on warning from Microsoft Visual C++ 2008.
Augie Fackler - Sept. 10, 2014, 7:20 p.m.
On Tue, Sep 09, 2014 at 07:51:42PM +0200, Henrik Stuart wrote:
> # HG changeset patch
> # User Henrik Stuart <hg@hstuart.dk>
> # Date 1410202664 -7200
> #      Mon Sep 08 20:57:44 2014 +0200
> # Node ID 86b438ac398f552a397f03b5f1b87352611db5ef
> # Parent  8bfb3cef896c160faec2659c4758fc9d3d28b1c4
> parsers: avoid signed/unsigned comparison mismatch

Queued the lot, thanks.

>
> Based on warning from Microsoft Visual C++ 2008.
>
> diff -r 8bfb3cef896c -r 86b438ac398f mercurial/parsers.c
> --- a/mercurial/parsers.c	Mon Sep 08 20:22:10 2014 +0200
> +++ b/mercurial/parsers.c	Mon Sep 08 20:57:44 2014 +0200
> @@ -275,15 +275,20 @@
>       PyObject *fname = NULL, *cname = NULL, *entry = NULL;
>       char state, *cur, *str, *cpos;
>       int mode, size, mtime;
> -	unsigned int flen;
> -	int len, pos = 40;
> +	unsigned int flen, len, pos = 40;
> +	int readlen;
>
>       if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate",
>                             &PyDict_Type, &dmap,
>                             &PyDict_Type, &cmap,
> -                           &str, &len))
> +                           &str, &readlen))
>               goto quit;
>
> +	if (readlen < 0)
> +		goto quit;
> +
> +	len = readlen;
> +
>       /* read parents */
>       if (len < 40)
>               goto quit;
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff -r 8bfb3cef896c -r 86b438ac398f mercurial/parsers.c
--- a/mercurial/parsers.c	Mon Sep 08 20:22:10 2014 +0200
+++ b/mercurial/parsers.c	Mon Sep 08 20:57:44 2014 +0200
@@ -275,15 +275,20 @@ 
 	PyObject *fname = NULL, *cname = NULL, *entry = NULL;
 	char state, *cur, *str, *cpos;
 	int mode, size, mtime;
-	unsigned int flen;
-	int len, pos = 40;
+	unsigned int flen, len, pos = 40;
+	int readlen;
 
 	if (!PyArg_ParseTuple(args, "O!O!s#:parse_dirstate",
 			      &PyDict_Type, &dmap,
 			      &PyDict_Type, &cmap,
-			      &str, &len))
+			      &str, &readlen))
 		goto quit;
 
+	if (readlen < 0)
+		goto quit;
+
+	len = readlen;
+
 	/* read parents */
 	if (len < 40)
 		goto quit;