Patchwork D4153: index: remove side-effect from failed nt_init()

login
register
mail settings
Submitter phabricator
Date Aug. 7, 2018, 12:52 p.m.
Message ID <8637a5c0c7fd3accdfb655b5a6fbdc6a@localhost.localdomain>
Download mbox | patch
Permalink /patch/33392/
State Not Applicable
Headers show

Comments

phabricator - Aug. 7, 2018, 12:52 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf7d8fb2ed8a8: index: remove side-effect from failed nt_init() (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4153?vs=10034&id=10048

REVISION DETAIL
  https://phab.mercurial-scm.org/D4153

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -1092,15 +1092,15 @@ 
 static int nt_init(indexObject *self)
 {
 	if (self->nt == NULL) {
+		if ((size_t)self->raw_length > INT_MAX / sizeof(nodetreenode)) {
+			PyErr_SetString(PyExc_ValueError, "overflow in nt_init");
+			return -1;
+		}
 		self->nt = PyMem_Malloc(sizeof(nodetree));
 		if (self->nt == NULL) {
 			PyErr_NoMemory();
 			return -1;
 		}
-		if ((size_t)self->raw_length > INT_MAX / sizeof(nodetreenode)) {
-			PyErr_SetString(PyExc_ValueError, "overflow in nt_init");
-			return -1;
-		}
 		self->nt->capacity = self->raw_length < 4
 			? 4 : (int)self->raw_length / 2;