summaryrefslogtreecommitdiff
path: root/Python
diff options
context:
space:
mode:
authorZackery Spytz <zspytz@gmail.com>2018-12-07 05:17:43 -0700
committerSerhiy Storchaka <storchaka@gmail.com>2018-12-07 14:17:43 +0200
commit602d307ac5e8a2da38a193dca3bdfef5994dfe67 (patch)
tree8e876e0142683a7564a391dc6396bc6d33f08639 /Python
parent2db190bb356d00422087e1286637887efb8d97c5 (diff)
downloadcpython-git-602d307ac5e8a2da38a193dca3bdfef5994dfe67.tar.gz
bpo-35436: Add missing PyErr_NoMemory() calls and other minor bug fixes. (GH-11015) (GH-11020)
(cherry picked from commit 4c49da0cb7434c676d70b9ccf38aca82ac0d64a9)
Diffstat (limited to 'Python')
-rw-r--r--Python/ast.c7
-rw-r--r--Python/marshal.c5
-rw-r--r--Python/pystrtod.c3
3 files changed, 12 insertions, 3 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 07227c238e..1e182c7d78 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -4092,6 +4092,9 @@ parsenumber(struct compiling *c, const char *s)
}
/* Create a duplicate without underscores. */
dup = PyMem_Malloc(strlen(s) + 1);
+ if (dup == NULL) {
+ return PyErr_NoMemory();
+ }
end = dup;
for (; *s; s++) {
if (*s != '_') {
@@ -4326,8 +4329,10 @@ fstring_compile_expr(const char *expr_start, const char *expr_end,
len = expr_end - expr_start;
/* Allocate 3 extra bytes: open paren, close paren, null byte. */
str = PyMem_RawMalloc(len + 3);
- if (str == NULL)
+ if (str == NULL) {
+ PyErr_NoMemory();
return NULL;
+ }
str[0] = '(';
memcpy(str+1, expr_start, len);
diff --git a/Python/marshal.c b/Python/marshal.c
index 6d06266c6a..7d60614e71 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -689,11 +689,12 @@ r_string(Py_ssize_t n, RFILE *p)
p->buf_size = n;
}
else if (p->buf_size < n) {
- p->buf = PyMem_REALLOC(p->buf, n);
- if (p->buf == NULL) {
+ char *tmp = PyMem_REALLOC(p->buf, n);
+ if (tmp == NULL) {
PyErr_NoMemory();
return NULL;
}
+ p->buf = tmp;
p->buf_size = n;
}
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index 461e8dcb5e..fea7e45c3b 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -398,6 +398,9 @@ _Py_string_to_number_with_underscores(
}
dup = PyMem_Malloc(orig_len + 1);
+ if (dup == NULL) {
+ return PyErr_NoMemory();
+ }
end = dup;
prev = '\0';
last = s + orig_len;