changeset 46224:fcc324a228fe

revlog: use size_t for nodetree capacity This allows handling revlog containing more than 33554432 (INT_MAX / sizeof(nodetreenode)) revisions on x64 platforms. Differential Revision: https://phab.mercurial-scm.org/D9745
author Jun Wu <quark@fb.com>
date Tue, 12 Jan 2021 14:45:32 -0800
parents 24bfd98978da
children 88dfe1c279bb
files mercurial/cext/revlog.c
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cext/revlog.c	Fri Jan 08 22:38:33 2021 +0530
+++ b/mercurial/cext/revlog.c	Tue Jan 12 14:45:32 2021 -0800
@@ -13,6 +13,7 @@
 #include <ctype.h>
 #include <limits.h>
 #include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -55,10 +56,10 @@
 	indexObject *index;
 	nodetreenode *nodes;
 	Py_ssize_t nodelen;
-	unsigned length;   /* # nodes in use */
-	unsigned capacity; /* # nodes allocated */
-	int depth;         /* maximum depth of tree */
-	int splits;        /* # splits performed */
+	size_t length;   /* # nodes in use */
+	size_t capacity; /* # nodes allocated */
+	int depth;       /* maximum depth of tree */
+	int splits;      /* # splits performed */
 } nodetree;
 
 typedef struct {
@@ -1536,10 +1537,10 @@
 static int nt_new(nodetree *self)
 {
 	if (self->length == self->capacity) {
-		unsigned newcapacity;
+		size_t newcapacity;
 		nodetreenode *newnodes;
 		newcapacity = self->capacity * 2;
-		if (newcapacity >= INT_MAX / sizeof(nodetreenode)) {
+		if (newcapacity >= SIZE_MAX / sizeof(nodetreenode)) {
 			PyErr_SetString(PyExc_MemoryError,
 			                "overflow in nt_new");
 			return -1;
@@ -1643,7 +1644,7 @@
 	self->nodelen = index->nodelen;
 	self->depth = 0;
 	self->splits = 0;
-	if ((size_t)self->capacity > INT_MAX / sizeof(nodetreenode)) {
+	if (self->capacity > SIZE_MAX / sizeof(nodetreenode)) {
 		PyErr_SetString(PyExc_ValueError, "overflow in init_nt");
 		return -1;
 	}