[Python-checkins] r42894 - in python/trunk: Modules/arraymodule.c Modules/cStringIO.c Modules/zipimport.c Objects/longobject.c Objects/stringobject.c Objects/unicodeobject.c Objects/weakrefobject.c Parser/firstsets.c Python/ast.c Python/ceval.c Python/traceback.c
hyeshik.chang
python-checkins at python.org
Tue Mar 7 16:39:24 CET 2006
Author: hyeshik.chang
Date: Tue Mar 7 16:39:21 2006
New Revision: 42894
Modified:
python/trunk/Modules/arraymodule.c
python/trunk/Modules/cStringIO.c
python/trunk/Modules/zipimport.c
python/trunk/Objects/longobject.c
python/trunk/Objects/stringobject.c
python/trunk/Objects/unicodeobject.c
python/trunk/Objects/weakrefobject.c
python/trunk/Parser/firstsets.c
python/trunk/Python/ast.c
python/trunk/Python/ceval.c
python/trunk/Python/traceback.c
Log:
SF #1444030: Fix several potential defects found by Coverity.
(reviewed by Neal Norwitz)
Modified: python/trunk/Modules/arraymodule.c
==============================================================================
--- python/trunk/Modules/arraymodule.c (original)
+++ python/trunk/Modules/arraymodule.c Tue Mar 7 16:39:21 2006
@@ -1852,10 +1852,13 @@
Py_DECREF(v);
}
} else if (initial != NULL && PyString_Check(initial)) {
- PyObject *t_initial = PyTuple_Pack(1,
- initial);
- PyObject *v =
- array_fromstring((arrayobject *)a,
+ PyObject *t_initial, *v;
+ t_initial = PyTuple_Pack(1, initial);
+ if (t_initial == NULL) {
+ Py_DECREF(a);
+ return NULL;
+ }
+ v = array_fromstring((arrayobject *)a,
t_initial);
Py_DECREF(t_initial);
if (v == NULL) {
Modified: python/trunk/Modules/cStringIO.c
==============================================================================
--- python/trunk/Modules/cStringIO.c (original)
+++ python/trunk/Modules/cStringIO.c Tue Mar 7 16:39:21 2006
@@ -544,6 +544,7 @@
if (!self->buf) {
PyErr_SetString(PyExc_MemoryError,"out of memory");
self->buf_size = 0;
+ Py_DECREF(self);
return NULL;
}
Modified: python/trunk/Modules/zipimport.c
==============================================================================
--- python/trunk/Modules/zipimport.c (original)
+++ python/trunk/Modules/zipimport.c Tue Mar 7 16:39:21 2006
@@ -1167,6 +1167,8 @@
mod = Py_InitModule4("zipimport", NULL, zipimport_doc,
NULL, PYTHON_API_VERSION);
+ if (mod == NULL)
+ return;
ZipImportError = PyErr_NewException("zipimport.ZipImportError",
PyExc_ImportError, NULL);
Modified: python/trunk/Objects/longobject.c
==============================================================================
--- python/trunk/Objects/longobject.c (original)
+++ python/trunk/Objects/longobject.c Tue Mar 7 16:39:21 2006
@@ -2809,6 +2809,8 @@
if (a->ob_size < 0) {
a = (PyLongObject *) long_invert(a);
+ if (a == NULL)
+ return NULL;
maska = MASK;
}
else {
@@ -2817,6 +2819,10 @@
}
if (b->ob_size < 0) {
b = (PyLongObject *) long_invert(b);
+ if (b == NULL) {
+ Py_DECREF(a);
+ return NULL;
+ }
maskb = MASK;
}
else {
@@ -2868,7 +2874,7 @@
: (maskb ? size_a : MIN(size_a, size_b)))
: MAX(size_a, size_b);
z = _PyLong_New(size_z);
- if (a == NULL || b == NULL || z == NULL) {
+ if (z == NULL) {
Py_XDECREF(a);
Py_XDECREF(b);
Py_XDECREF(z);
Modified: python/trunk/Objects/stringobject.c
==============================================================================
--- python/trunk/Objects/stringobject.c (original)
+++ python/trunk/Objects/stringobject.c Tue Mar 7 16:39:21 2006
@@ -3276,7 +3276,7 @@
return list;
onError:
- Py_DECREF(list);
+ Py_XDECREF(list);
return NULL;
}
Modified: python/trunk/Objects/unicodeobject.c
==============================================================================
--- python/trunk/Objects/unicodeobject.c (original)
+++ python/trunk/Objects/unicodeobject.c Tue Mar 7 16:39:21 2006
@@ -1876,16 +1876,16 @@
message = "malformed \\N character escape";
if (ucnhash_CAPI == NULL) {
/* load the unicode data module */
- PyObject *m, *v;
+ PyObject *m, *api;
m = PyImport_ImportModule("unicodedata");
if (m == NULL)
goto ucnhashError;
- v = PyObject_GetAttrString(m, "ucnhash_CAPI");
+ api = PyObject_GetAttrString(m, "ucnhash_CAPI");
Py_DECREF(m);
- if (v == NULL)
+ if (api == NULL)
goto ucnhashError;
- ucnhash_CAPI = PyCObject_AsVoidPtr(v);
- Py_DECREF(v);
+ ucnhash_CAPI = PyCObject_AsVoidPtr(api);
+ Py_DECREF(api);
if (ucnhash_CAPI == NULL)
goto ucnhashError;
}
@@ -1945,6 +1945,7 @@
PyExc_UnicodeError,
"\\N escapes not supported (can't load unicodedata module)"
);
+ Py_XDECREF(v);
Py_XDECREF(errorHandler);
Py_XDECREF(exc);
return NULL;
@@ -3962,7 +3963,7 @@
return -1;
substr = PyUnicode_FromObject(substr);
if (substr == NULL) {
- Py_DECREF(substr);
+ Py_DECREF(str);
return -1;
}
@@ -4429,7 +4430,7 @@
return list;
onError:
- Py_DECREF(list);
+ Py_XDECREF(list);
Py_DECREF(string);
return NULL;
}
@@ -6679,6 +6680,10 @@
if (!str)
return NULL;
result = _PyUnicode_New(len);
+ if (!result) {
+ Py_DECREF(str);
+ return NULL;
+ }
for (i = 0; i < len; i++)
result->str[i] = buf[i];
result->str[len] = 0;
@@ -6865,7 +6870,7 @@
rescnt = fmtcnt + 100;
reslen += rescnt;
if (_PyUnicode_Resize(&result, reslen) < 0)
- return NULL;
+ goto onError;
res = PyUnicode_AS_UNICODE(result) + reslen - rescnt;
--rescnt;
}
@@ -7163,6 +7168,7 @@
rescnt = width + fmtcnt + 100;
reslen += rescnt;
if (reslen < 0) {
+ Py_XDECREF(temp);
Py_DECREF(result);
return PyErr_NoMemory();
}
Modified: python/trunk/Objects/weakrefobject.c
==============================================================================
--- python/trunk/Objects/weakrefobject.c (original)
+++ python/trunk/Objects/weakrefobject.c Tue Mar 7 16:39:21 2006
@@ -903,8 +903,15 @@
}
}
else {
- PyObject *tuple = PyTuple_New(count * 2);
+ PyObject *tuple;
Py_ssize_t i = 0;
+
+ tuple = PyTuple_New(count * 2);
+ if (tuple == NULL) {
+ if (restore_error)
+ PyErr_Fetch(&err_type, &err_value, &err_tb);
+ return;
+ }
for (i = 0; i < count; ++i) {
PyWeakReference *next = current->wr_next;
Modified: python/trunk/Parser/firstsets.c
==============================================================================
--- python/trunk/Parser/firstsets.c (original)
+++ python/trunk/Parser/firstsets.c Tue Mar 7 16:39:21 2006
@@ -107,4 +107,6 @@
}
printf(" }\n");
}
+
+ PyMem_FREE(sym);
}
Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c (original)
+++ python/trunk/Python/ast.c Tue Mar 7 16:39:21 2006
@@ -1438,6 +1438,8 @@
}
/* extract Index values and put them in a Tuple */
elts = asdl_seq_new(asdl_seq_LEN(slices), c->c_arena);
+ if (!elts)
+ return NULL;
for (j = 0; j < asdl_seq_LEN(slices); ++j) {
slc = (slice_ty)asdl_seq_GET(slices, j);
assert(slc->kind == Index_kind && slc->v.Index.value);
Modified: python/trunk/Python/ceval.c
==============================================================================
--- python/trunk/Python/ceval.c (original)
+++ python/trunk/Python/ceval.c Tue Mar 7 16:39:21 2006
@@ -3477,8 +3477,11 @@
{
PyObject *result;
- if (arg == NULL)
+ if (arg == NULL) {
arg = PyTuple_New(0);
+ if (arg == NULL)
+ return NULL;
+ }
else if (!PyTuple_Check(arg)) {
PyErr_SetString(PyExc_TypeError,
"argument list must be a tuple");
Modified: python/trunk/Python/traceback.c
==============================================================================
--- python/trunk/Python/traceback.c (original)
+++ python/trunk/Python/traceback.c Tue Mar 7 16:39:21 2006
@@ -185,8 +185,12 @@
}
PyOS_snprintf(linebuf, sizeof(linebuf), FMT, filename, lineno, name);
err = PyFile_WriteString(linebuf, f);
- if (xfp == NULL || err != 0)
+ if (xfp == NULL)
return err;
+ else if (err != 0) {
+ fclose(xfp);
+ return err;
+ }
for (i = 0; i < lineno; i++) {
char* pLastChar = &linebuf[sizeof(linebuf)-2];
do {
More information about the Python-checkins
mailing list