summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1997-01-10 18:42:18 (GMT)
committerBarry Warsaw <barry@python.org>1997-01-10 18:42:18 (GMT)
commit5709dcfaec57f014452fcd4f06abb64692f0d91f (patch)
tree95ca55e7e5c1f1bfa92cac714233f0f0bdb30983 /Modules
parent4de02d97225932ebfd01dd83acf85ed5bc5455e9 (diff)
downloadcpython-5709dcfaec57f014452fcd4f06abb64692f0d91f.zip
cpython-5709dcfaec57f014452fcd4f06abb64692f0d91f.tar.gz
cpython-5709dcfaec57f014452fcd4f06abb64692f0d91f.tar.bz2
The usual return-value and memory management checks. I'm not planning
a test for this module though (it does compile at least on Solaris 2.5)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/termios.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/Modules/termios.c b/Modules/termios.c
index 75f77a5..5dfe57f 100644
--- a/Modules/termios.c
+++ b/Modules/termios.c
@@ -45,7 +45,7 @@ termios_tcgetattr(self, args)
ch = (char)mode.c_cc[i];
v = PyString_FromStringAndSize(&ch, 1);
if (v == NULL)
- return NULL;
+ goto err;
PyList_SetItem(cc, i, v);
}
@@ -55,15 +55,17 @@ termios_tcgetattr(self, args)
if ((mode.c_lflag & ICANON) == 0) {
v = PyInt_FromLong((long)mode.c_cc[VMIN]);
if (v == NULL)
- return NULL;
+ goto err;
PyList_SetItem(cc, VMIN, v);
v = PyInt_FromLong((long)mode.c_cc[VTIME]);
if (v == NULL)
- return NULL;
+ goto err;
PyList_SetItem(cc, VTIME, v);
}
- v = PyList_New(7);
+ if (!(v = PyList_New(7)))
+ goto err;
+
PyList_SetItem(v, 0, PyInt_FromLong((long)mode.c_iflag));
PyList_SetItem(v, 1, PyInt_FromLong((long)mode.c_oflag));
PyList_SetItem(v, 2, PyInt_FromLong((long)mode.c_cflag));
@@ -71,8 +73,14 @@ termios_tcgetattr(self, args)
PyList_SetItem(v, 4, PyInt_FromLong((long)ispeed));
PyList_SetItem(v, 5, PyInt_FromLong((long)ospeed));
PyList_SetItem(v, 6, cc);
-
+ if (PyErr_Occurred()){
+ Py_DECREF(v);
+ goto err;
+ }
return v;
+ err:
+ Py_DECREF(cc);
+ return NULL;
}
/* tcsetattr(fd, when, termios)
@@ -95,11 +103,6 @@ termios_tcsetattr(self, args)
PyErr_SetString(PyExc_TypeError, BAD);
return NULL;
}
- for (i = 0; i < 6; i++)
- if (!PyInt_Check(PyList_GetItem(term, i))) {
- PyErr_SetString(PyExc_TypeError, BAD);
- return NULL;
- }
mode.c_iflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 0));
mode.c_oflag = (tcflag_t) PyInt_AsLong(PyList_GetItem(term, 1));
@@ -108,6 +111,8 @@ termios_tcsetattr(self, args)
ispeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 4));
ospeed = (speed_t) PyInt_AsLong(PyList_GetItem(term, 5));
cc = PyList_GetItem(term, 6);
+ if (PyErr_Occurred())
+ return NULL;
if (!PyList_Check(cc) || PyList_Size(cc) != NCCS) {
PyErr_SetString(PyExc_TypeError, BAD);
@@ -116,6 +121,7 @@ termios_tcsetattr(self, args)
for (i = 0; i < NCCS; i++) {
v = PyList_GetItem(cc, i);
+
if (PyString_Check(v) && PyString_Size(v) == 1)
mode.c_cc[i] = (cc_t) * PyString_AsString(v);
else if (PyInt_Check(v))