Mercurial > hg
changeset 39071:06ff7ea4f440
index: avoid duplicating capacity-growth expression
We were duplicating the "*2" instead of reusing it. It's overflow-safe
to reuse as long as the growth factor (i.e. currently 2) is not larger
than sizeof(nodetreenode) (currently 64 or 128).
Differential Revision: https://phab.mercurial-scm.org/D4165
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 08 Aug 2018 23:41:50 -0700 |
parents | 4dd92a15fcca |
children | 34eb999e29bf |
files | mercurial/cext/revlog.c |
diffstat | 1 files changed, 3 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/cext/revlog.c Wed Aug 08 23:36:15 2018 -0700 +++ b/mercurial/cext/revlog.c Wed Aug 08 23:41:50 2018 -0700 @@ -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");