summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2004-11-07 14:04:00 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2004-11-07 14:04:00 (GMT)
commit16b047904ca59831c28bcb811647f9f81590f1c8 (patch)
treee678a77c775e10df7280978c4c3f72b52f9adb07 /Python
parent84a6c205e3582b5a8705baf9720124c22f74ae4c (diff)
downloadcpython-16b047904ca59831c28bcb811647f9f81590f1c8.zip
cpython-16b047904ca59831c28bcb811647f9f81590f1c8.tar.gz
cpython-16b047904ca59831c28bcb811647f9f81590f1c8.tar.bz2
SF patch 1025636: Check for NULL returns in compile.c:com_import_stmt
There is no test for this change, because there is no way to provoke memory errors on demand. Test suite passes, though.
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c
index be81ba0..ea325ff 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -3606,10 +3606,20 @@ com_import_stmt(struct compiling *c, node *n)
}
REQ(nn, import_as_names);
tup = PyTuple_New((NCH(nn) + 1) / 2);
- for (i = 0; i < NCH(nn); i += 2)
- PyTuple_SET_ITEM(tup, i / 2,
- PyString_FromString(STR(
- CHILD(CHILD(nn, i), 0))));
+ for (i = 0; i < NCH(nn); i += 2) {
+ PyObject *s = PyString_FromString(
+ STR(CHILD(CHILD(nn, i), 0)));
+ if (s == NULL) {
+ Py_CLEAR(tup);
+ break;
+ } else
+ PyTuple_SET_ITEM(tup, i / 2, s);
+ }
+ if (tup == NULL) {
+ /* Assume that failue above was MemoryError */
+ com_error(c, PyExc_MemoryError, "");
+ return;
+ }
}
com_addoparg(c, LOAD_CONST, com_addconst(c, tup));
Py_DECREF(tup);