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

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;
        }



To: quark, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to