comparison mercurial/cext/revlog.c @ 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
comparison
equal deleted inserted replaced
39070:4dd92a15fcca 39071:06ff7ea4f440
989 static int nt_new(nodetree *self) 989 static int nt_new(nodetree *self)
990 { 990 {
991 if (self->length == self->capacity) { 991 if (self->length == self->capacity) {
992 unsigned newcapacity; 992 unsigned newcapacity;
993 nodetreenode *newnodes; 993 nodetreenode *newnodes;
994 if (self->capacity >= INT_MAX / (sizeof(nodetreenode) * 2)) { 994 newcapacity = self->capacity * 2;
995 PyErr_SetString(PyExc_MemoryError, 995 if (newcapacity >= INT_MAX / sizeof(nodetreenode)) {
996 "overflow in nt_new"); 996 PyErr_SetString(PyExc_MemoryError, "overflow in nt_new");
997 return -1; 997 return -1;
998 } 998 }
999 newcapacity = self->capacity * 2;
1000 newnodes = realloc(self->nodes, newcapacity * sizeof(nodetreenode)); 999 newnodes = realloc(self->nodes, newcapacity * sizeof(nodetreenode));
1001 if (newnodes == NULL) { 1000 if (newnodes == NULL) {
1002 PyErr_SetString(PyExc_MemoryError, "out of memory"); 1001 PyErr_SetString(PyExc_MemoryError, "out of memory");
1003 return -1; 1002 return -1;
1004 } 1003 }