summaryrefslogtreecommitdiff
path: root/Objects
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2006-10-03 18:43:28 +0000
committerAndrew M. Kuchling <amk@amk.ca>2006-10-03 18:43:28 +0000
commit5cf2fb9904ceba3e7dd07aeb325f44a1cd8070bf (patch)
tree0c7f0d3d85f4fc13fe574883088d9dbfd9ee7078 /Objects
parent91697928ca2813d82a4cd0b6908590bae62d7fa4 (diff)
downloadcpython-git-5cf2fb9904ceba3e7dd07aeb325f44a1cd8070bf.tar.gz
[Backport r50683 | neal.norwitz]
Stop INCREFing name, then checking if it's NULL. name (f_name) should never be NULL so assert it. Fix one place where we could have passed NULL. Reported by Klocwork #66.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/fileobject.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 4f5720cde1..a66846c0ed 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -98,6 +98,7 @@ static PyObject *
fill_file_fields(PyFileObject *f, FILE *fp, PyObject *name, char *mode,
int (*close)(FILE *))
{
+ assert(name != NULL);
assert(f != NULL);
assert(PyFile_Check(f));
assert(f->f_fp == NULL);
@@ -106,7 +107,7 @@ fill_file_fields(PyFileObject *f, FILE *fp, PyObject *name, char *mode,
Py_DECREF(f->f_mode);
Py_DECREF(f->f_encoding);
- Py_INCREF (name);
+ Py_INCREF(name);
f->f_name = name;
f->f_mode = PyString_FromString(mode);
@@ -121,7 +122,7 @@ fill_file_fields(PyFileObject *f, FILE *fp, PyObject *name, char *mode,
Py_INCREF(Py_None);
f->f_encoding = Py_None;
- if (f->f_name == NULL || f->f_mode == NULL)
+ if (f->f_mode == NULL)
return NULL;
f->f_fp = fp;
f = dircheck(f);
@@ -207,7 +208,9 @@ PyFile_FromFile(FILE *fp, char *name, char *mode, int (*close)(FILE *))
PyFileObject *f = (PyFileObject *)PyFile_Type.tp_new(&PyFile_Type,
NULL, NULL);
if (f != NULL) {
- PyObject *o_name = PyString_FromString(name);
+ PyObject *o_name = PyString_FromString(name);
+ if (o_name == NULL)
+ return NULL;
if (fill_file_fields(f, fp, o_name, mode, close) == NULL) {
Py_DECREF(f);
f = NULL;