parsers: avoid signed/unsigned comparison mismatch
authorHenrik Stuart <hg@hstuart.dk>
Mon, 08 Sep 2014 20:57:44 +0200
changeset 22403 41e9d58ec56f
parent 22402 fa53d66b45a8
child 22404 12bc7f06fc41
parsers: avoid signed/unsigned comparison mismatch Based on warning from Microsoft Visual C++ 2008.
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;