[Python-checkins] r46497 - python/trunk/Python/errors.c python/trunk/Python/pythonrun.c
tim.peters
python-checkins at python.org
Sun May 28 12:41:30 CEST 2006
Author: tim.peters
Date: Sun May 28 12:41:29 2006
New Revision: 46497
Modified:
python/trunk/Python/errors.c
python/trunk/Python/pythonrun.c
Log:
PyErr_Display(), PyErr_WriteUnraisable(): Coverity found a cut-and-paste
bug in both: `className` was referenced before being checked for NULL.
Modified: python/trunk/Python/errors.c
==============================================================================
--- python/trunk/Python/errors.c (original)
+++ python/trunk/Python/errors.c Sun May 28 12:41:29 2006
@@ -588,13 +588,16 @@
if (f != NULL) {
PyFile_WriteString("Exception ", f);
if (t) {
- char* className = PyExceptionClass_Name(t);
PyObject* moduleName;
- char *dot = strrchr(className, '.');
- if (dot != NULL)
- className = dot+1;
- moduleName = PyObject_GetAttrString(t, "__module__");
+ char* className = PyExceptionClass_Name(t);
+ if (className != NULL) {
+ char *dot = strrchr(className, '.');
+ if (dot != NULL)
+ className = dot+1;
+ }
+
+ moduleName = PyObject_GetAttrString(t, "__module__");
if (moduleName == NULL)
PyFile_WriteString("<unknown>", f);
else {
Modified: python/trunk/Python/pythonrun.c
==============================================================================
--- python/trunk/Python/pythonrun.c (original)
+++ python/trunk/Python/pythonrun.c Sun May 28 12:41:29 2006
@@ -663,7 +663,7 @@
/* Parse input from a file and execute it */
int
-PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit,
+PyRun_AnyFileExFlags(FILE *fp, const char *filename, int closeit,
PyCompilerFlags *flags)
{
if (filename == NULL)
@@ -744,7 +744,7 @@
ps2 = PyString_AsString(w);
}
arena = PyArena_New();
- mod = PyParser_ASTFromFile(fp, filename,
+ mod = PyParser_ASTFromFile(fp, filename,
Py_single_input, ps1, ps2,
flags, &errcode, arena);
Py_XDECREF(v);
@@ -1132,13 +1132,15 @@
/* Don't do anything else */
}
else if (PyExceptionClass_Check(exception)) {
- char* className = PyExceptionClass_Name(exception);
- char *dot = strrchr(className, '.');
PyObject* moduleName;
- if (dot != NULL)
- className = dot+1;
- moduleName = PyObject_GetAttrString(exception, "__module__");
+ char* className = PyExceptionClass_Name(exception);
+ if (className != NULL) {
+ char *dot = strrchr(className, '.');
+ if (dot != NULL)
+ className = dot+1;
+ }
+ moduleName = PyObject_GetAttrString(exception, "__module__");
if (moduleName == NULL)
err = PyFile_WriteString("<unknown>", f);
else {
@@ -1184,7 +1186,7 @@
}
PyObject *
-PyRun_StringFlags(const char *str, int start, PyObject *globals,
+PyRun_StringFlags(const char *str, int start, PyObject *globals,
PyObject *locals, PyCompilerFlags *flags)
{
PyObject *ret = NULL;
@@ -1231,7 +1233,7 @@
}
static PyObject *
-run_pyc_file(FILE *fp, const char *filename, PyObject *globals,
+run_pyc_file(FILE *fp, const char *filename, PyObject *globals,
PyObject *locals, PyCompilerFlags *flags)
{
PyCodeObject *co;
@@ -1300,13 +1302,13 @@
/* Preferred access to parser is through AST. */
mod_ty
-PyParser_ASTFromString(const char *s, const char *filename, int start,
+PyParser_ASTFromString(const char *s, const char *filename, int start,
PyCompilerFlags *flags, PyArena *arena)
{
mod_ty mod;
perrdetail err;
node *n = PyParser_ParseStringFlagsFilename(s, filename,
- &_PyParser_Grammar, start, &err,
+ &_PyParser_Grammar, start, &err,
PARSER_FLAGS(flags));
if (n) {
mod = PyAST_FromNode(n, flags, filename, arena);
@@ -1320,7 +1322,7 @@
}
mod_ty
-PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1,
+PyParser_ASTFromFile(FILE *fp, const char *filename, int start, char *ps1,
char *ps2, PyCompilerFlags *flags, int *errcode,
PyArena *arena)
{
@@ -1351,7 +1353,7 @@
start, NULL, NULL, &err, flags);
if (n == NULL)
err_input(&err);
-
+
return n;
}
More information about the Python-checkins
mailing list