Patchwork D9745: revlog: use size_t for nodetree capacity

login
register
mail settings
Submitter phabricator
Date Jan. 12, 2021, 10:51 p.m.
Message ID <differential-rev-PHID-DREV-zgs5rmhqcxtbmhzgxulo-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48056/
State Superseded
Headers show

Comments

phabricator - Jan. 12, 2021, 10:51 p.m.
quark created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  This allows handling revlog containing more than 33554432 (INT_MAX /
  sizeof(nodetreenode)) revisions on x64 platforms.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cext/revlog.c

CHANGE DETAILS




To: quark, #hg-reviewers
Cc: mercurial-patches, 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
@@ -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;
 	}