D4165: index: avoid duplicating capacity-growth expression

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Sun Aug 12 00:46:15 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG06ff7ea4f440: index: avoid duplicating capacity-growth expression (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4165?vs=10091&id=10338

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

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS

diff --git a/mercurial/cext/revlog.c b/mercurial/cext/revlog.c
--- a/mercurial/cext/revlog.c
+++ b/mercurial/cext/revlog.c
@@ -991,12 +991,11 @@
 	if (self->length == self->capacity) {
 		unsigned newcapacity;
 		nodetreenode *newnodes;
-		if (self->capacity >= INT_MAX / (sizeof(nodetreenode) * 2)) {
-			PyErr_SetString(PyExc_MemoryError,
-					"overflow in nt_new");
+		newcapacity = self->capacity * 2;
+		if (newcapacity >= INT_MAX / sizeof(nodetreenode)) {
+			PyErr_SetString(PyExc_MemoryError, "overflow in nt_new");
 			return -1;
 		}
-		newcapacity = self->capacity * 2;
 		newnodes = realloc(self->nodes, newcapacity * sizeof(nodetreenode));
 		if (newnodes == NULL) {
 			PyErr_SetString(PyExc_MemoryError, "out of memory");



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


More information about the Mercurial-devel mailing list