[PATCH] parsers.c: remove warning: 'size' may be used uninitialized in this function

Mads Kiilerich mads at kiilerich.com
Thu Jul 5 18:11:03 CDT 2012


# HG changeset patch
# User Mads Kiilerich <mads at kiilerich.com>
# Date 1341528525 -7200
# Node ID 52dd5f82bac4cd49845ee755c48c10e7ccb0db8b
# Parent  01d847e0fdc9578ae2f94b42291bcb6a6e5bf89e
parsers.c: remove warning: 'size' may be used uninitialized in this function

Some compilers / compiler options (such as gcc 4.7) would emit warnings:

mercurial/parsers.c: In function 'pack_dirstate':
mercurial/parsers.c:306:18: warning: 'size' may be used uninitialized in this function [-Wmaybe-uninitialized]
mercurial/parsers.c:306:12: warning: 'mode' may be used uninitialized in this function [-Wmaybe-uninitialized]

It is apparently not smart enough to figure out how the 'err' arithmetics makes
sure that it can't happen.

'err' is now replaced with simple checks and goto. That might also help the
optimizer when it is inlining getintat().

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -307,7 +307,6 @@
 		Py_ssize_t len, l;
 		PyObject *o;
 		char *s, *t;
-		int err;
 
 		if (!PyTuple_Check(v) || PyTuple_GET_SIZE(v) != 4) {
 			PyErr_SetString(PyExc_TypeError, "expected a 4-tuple");
@@ -319,10 +318,11 @@
 			goto bail;
 		}
 		*p++ = *s;
-		err = getintat(v, 1, &mode);
-		err |= getintat(v, 2, &size);
-		err |= getintat(v, 3, &mtime);
-		if (err)
+		if (getintat(v, 1, &mode) == -1)
+			goto bail;
+		if (getintat(v, 2, &size) == -1)
+			goto bail;
+		if (getintat(v, 3, &mtime) == -1)
 			goto bail;
 		if (*s == 'n' && mtime == (uint32_t)now) {
 			/* See dirstate.py:write for why we do this. */


More information about the Mercurial-devel mailing list