changeset 39070:4dd92a15fcca

index: move check for too large capacity into nt_init() It's clearer to have the check just before the allocation happens. Differential Revision: https://phab.mercurial-scm.org/D4164
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 08 Aug 2018 23:36:15 -0700
parents 4c4825db29e1
children 06ff7ea4f440
files mercurial/cext/revlog.c
diffstat 1 files changed, 4 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Wed Aug 08 22:26:57 2018 -0700
+++ b/mercurial/cext/revlog.c	Wed Aug 08 23:36:15 2018 -0700
@@ -1069,6 +1069,10 @@
 	self->capacity = capacity;
 	self->depth = 0;
 	self->splits = 0;
+	if ((size_t)self->capacity > INT_MAX / sizeof(nodetreenode)) {
+		PyErr_SetString(PyExc_ValueError, "overflow in init_nt");
+		return -1;
+	}
 	self->nodes = calloc(self->capacity, sizeof(nodetreenode));
 	if (self->nodes == NULL) {
 		PyErr_NoMemory();
@@ -1133,10 +1137,6 @@
 static int index_init_nt(indexObject *self)
 {
 	if (self->nt == NULL) {
-		if ((size_t)self->raw_length > INT_MAX / sizeof(nodetreenode)) {
-			PyErr_SetString(PyExc_ValueError, "overflow in index_init_nt");
-			return -1;
-		}
 		self->nt = PyMem_Malloc(sizeof(nodetree));
 		if (self->nt == NULL) {
 			PyErr_NoMemory();