Patchwork [2,of,4] parsers: check results of PyInt_FromLong (issue4771)

login
register
mail settings
Submitter Bryan O'Sullivan
Date Dec. 14, 2015, 6:49 p.m.
Message ID <13a42f5695ac05f1a684.1450118963@bryano-mbp.local>
Download mbox | patch
Permalink /patch/12033/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Bryan O'Sullivan - Dec. 14, 2015, 6:49 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bos@serpentine.com>
# Date 1450118846 28800
#      Mon Dec 14 10:47:26 2015 -0800
# Node ID 13a42f5695ac05f1a684070d5e6516286dc4ce8d
# Parent  f87799029bb6c39860b9eede0ae54a8dfece8c01
parsers: check results of PyInt_FromLong (issue4771)

Patch

diff --git a/mercurial/parsers.c b/mercurial/parsers.c
--- a/mercurial/parsers.c
+++ b/mercurial/parsers.c
@@ -1333,16 +1333,23 @@  static PyObject *compute_phases_map_sets
 	if (phaseslist == NULL)
 		goto release;
 	for (i = 0; i < len; i++) {
+		PyObject *phaseval;
+
 		phase = phases[i];
 		/* We only store the sets of phase for non public phase, the public phase
 		 * is computed as a difference */
 		if (phase != 0) {
 			phaseset = PyList_GET_ITEM(phasessetlist, phase);
 			rev = PyInt_FromLong(i);
+			if (rev == NULL)
+				goto release;
 			PySet_Add(phaseset, rev);
 			Py_XDECREF(rev);
 		}
-		PyList_SET_ITEM(phaseslist, i, PyInt_FromLong(phase));
+		phaseval = PyInt_FromLong(phase);
+		if (phaseval == NULL)
+			goto release;
+		PyList_SET_ITEM(phaseslist, i, phaseval);
 	}
 	ret = PyList_New(2);
 	if (ret == NULL)