Show More
@@ -1015,26 +1015,25 b' static int nt_find(indexObject *self, co' | |||||
1015 | return -4; |
|
1015 | return -4; | |
1016 | } |
|
1016 | } | |
1017 |
|
1017 | |||
1018 |
static int nt_new( |
|
1018 | static int nt_new(nodetree *self) | |
1019 | { |
|
1019 | { | |
1020 | nodetree *nt = self->nt; |
|
1020 | if (self->length == self->capacity) { | |
1021 | if (nt->length == nt->capacity) { |
|
1021 | if (self->capacity >= INT_MAX / (sizeof(nodetreenode) * 2)) { | |
1022 | if (nt->capacity >= INT_MAX / (sizeof(nodetreenode) * 2)) { |
|
|||
1023 | PyErr_SetString(PyExc_MemoryError, |
|
1022 | PyErr_SetString(PyExc_MemoryError, | |
1024 | "overflow in nt_new"); |
|
1023 | "overflow in nt_new"); | |
1025 | return -1; |
|
1024 | return -1; | |
1026 | } |
|
1025 | } | |
1027 |
|
|
1026 | self->capacity *= 2; | |
1028 |
|
|
1027 | self->nodes = realloc(self->nodes, | |
1029 |
|
|
1028 | self->capacity * sizeof(nodetreenode)); | |
1030 |
if ( |
|
1029 | if (self->nodes == NULL) { | |
1031 | PyErr_SetString(PyExc_MemoryError, "out of memory"); |
|
1030 | PyErr_SetString(PyExc_MemoryError, "out of memory"); | |
1032 | return -1; |
|
1031 | return -1; | |
1033 | } |
|
1032 | } | |
1034 |
memset(& |
|
1033 | memset(&self->nodes[self->length], 0, | |
1035 |
sizeof(nodetreenode) * ( |
|
1034 | sizeof(nodetreenode) * (self->capacity - self->length)); | |
1036 | } |
|
1035 | } | |
1037 |
return |
|
1036 | return self->length++; | |
1038 | } |
|
1037 | } | |
1039 |
|
1038 | |||
1040 | static int nt_insert(indexObject *self, const char *node, int rev) |
|
1039 | static int nt_insert(indexObject *self, const char *node, int rev) | |
@@ -1064,7 +1063,7 b' static int nt_insert(indexObject *self, ' | |||||
1064 | n->children[k] = -rev - 2; |
|
1063 | n->children[k] = -rev - 2; | |
1065 | return 0; |
|
1064 | return 0; | |
1066 | } |
|
1065 | } | |
1067 | noff = nt_new(self); |
|
1066 | noff = nt_new(self->nt); | |
1068 | if (noff == -1) |
|
1067 | if (noff == -1) | |
1069 | return -1; |
|
1068 | return -1; | |
1070 | /* self->nt->nodes may have been changed by realloc */ |
|
1069 | /* self->nt->nodes may have been changed by realloc */ |
General Comments 0
You need to be logged in to leave comments.
Login now