summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Python/import.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/Python/import.c b/Python/import.c
index d5dad1a..8d30640 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -2291,7 +2291,7 @@ int
PyImport_ExtendInittab(struct _inittab *newtab)
{
struct _inittab *p;
- Py_ssize_t i, n;
+ size_t i, n;
int res = 0;
/* Count the number of entries in both tables */
@@ -2308,13 +2308,11 @@ PyImport_ExtendInittab(struct _inittab *newtab)
_PyMem_SetDefaultAllocator(PYMEM_DOMAIN_RAW, &old_alloc);
/* Allocate new memory for the combined table */
- if ((i + n + 1) <= PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(struct _inittab)) {
+ p = NULL;
+ if (i + n <= SIZE_MAX / sizeof(struct _inittab) - 1) {
size_t size = sizeof(struct _inittab) * (i + n + 1);
p = PyMem_RawRealloc(inittab_copy, size);
}
- else {
- p = NULL;
- }
if (p == NULL) {
res = -1;
goto done;