[Python-checkins] r51218 - in python/trunk: Misc/README.klocwork Modules/_codecsmodule.c Modules/_elementtree.c Modules/_hotshot.c Modules/arraymodule.c Objects/structseq.c Python/ast.c Python/symtable.c

neal.norwitz python-checkins at python.org
Sat Aug 12 03:43:42 CEST 2006


Author: neal.norwitz
Date: Sat Aug 12 03:43:40 2006
New Revision: 51218

Modified:
   python/trunk/Misc/README.klocwork
   python/trunk/Modules/_codecsmodule.c
   python/trunk/Modules/_elementtree.c
   python/trunk/Modules/_hotshot.c
   python/trunk/Modules/arraymodule.c
   python/trunk/Objects/structseq.c
   python/trunk/Python/ast.c
   python/trunk/Python/symtable.c
Log:
Klocwork made another run and found a bunch more problems.  
This is the first batch of fixes that should be easy to verify based on context.

This fixes problem numbers: 220 (ast), 323-324 (symtable),
321-322 (structseq), 215 (array), 210 (hotshot), 182 (codecs), 209 (etree).


Modified: python/trunk/Misc/README.klocwork
==============================================================================
--- python/trunk/Misc/README.klocwork	(original)
+++ python/trunk/Misc/README.klocwork	Sat Aug 12 03:43:40 2006
@@ -23,4 +23,8 @@
 False positives were also annotated so that the comments can
 be reviewed and reversed if the analysis was incorrect.
 
+A second run was performed on 10-Aug-2006.  The tool was tuned to remove
+some false positives and perform some additional checks.  ~150 new
+warnings were produced, primarily related to dereferencing NULL pointers.
+
 Contact python-dev at python.org for more information.

Modified: python/trunk/Modules/_codecsmodule.c
==============================================================================
--- python/trunk/Modules/_codecsmodule.c	(original)
+++ python/trunk/Modules/_codecsmodule.c	Sat Aug 12 03:43:40 2006
@@ -192,7 +192,8 @@
 	buf = PyString_AS_STRING (str);
 	len = PyString_GET_SIZE (str);
 	memmove(buf, buf+1, len-2);
-	_PyString_Resize(&str, len-2);
+	if (_PyString_Resize(&str, len-2) < 0)
+		return NULL;
 	
 	return codec_tuple(str, PyString_Size(str));
 }

Modified: python/trunk/Modules/_elementtree.c
==============================================================================
--- python/trunk/Modules/_elementtree.c	(original)
+++ python/trunk/Modules/_elementtree.c	Sat Aug 12 03:43:40 2006
@@ -809,7 +809,7 @@
             PyObject* text = element_get_text(item);
             if (text == Py_None)
                 return PyString_FromString("");
-            Py_INCREF(text);
+            Py_XINCREF(text);
             return text;
         }
     }

Modified: python/trunk/Modules/_hotshot.c
==============================================================================
--- python/trunk/Modules/_hotshot.c	(original)
+++ python/trunk/Modules/_hotshot.c	Sat Aug 12 03:43:40 2006
@@ -313,6 +313,11 @@
         return err;
 
     buf = (char *)malloc(len);
+    if (!buf) {
+	PyErr_NoMemory();
+	return ERR_EXCEPTION;
+    }
+
     for (i=0; i < len; i++) {
         ch = fgetc(self->logfp);
 	buf[i] = ch;

Modified: python/trunk/Modules/arraymodule.c
==============================================================================
--- python/trunk/Modules/arraymodule.c	(original)
+++ python/trunk/Modules/arraymodule.c	Sat Aug 12 03:43:40 2006
@@ -702,6 +702,8 @@
 			/* Special case "a[i:j] = a" -- copy b first */
 			int ret;
 			v = array_slice(b, 0, n);
+			if (!v)
+				return -1;
 			ret = array_ass_slice(a, ilow, ihigh, v);
 			Py_DECREF(v);
 			return ret;
@@ -1708,6 +1710,8 @@
 			if (self == av) { 
 				value = array_slice(av, 0, av->ob_size);
 				av = (arrayobject*)value;
+				if (!av)
+					return -1;
 			} 
 			else {
 				Py_INCREF(value);

Modified: python/trunk/Objects/structseq.c
==============================================================================
--- python/trunk/Objects/structseq.c	(original)
+++ python/trunk/Objects/structseq.c	Sat Aug 12 03:43:40 2006
@@ -215,6 +215,8 @@
 	PyObject *tup;
 	int result;
 	tup = make_tuple(obj);
+	if (!tup)
+		return -1;
 	result = PySequence_Contains(tup, o);
 	Py_DECREF(tup);
 	return result;
@@ -226,6 +228,8 @@
 	PyObject *tup;
 	long result;
 	tup = make_tuple((PyStructSequence*) obj);
+	if (!tup)
+		return -1;
 	result = PyObject_Hash(tup);
 	Py_DECREF(tup);
 	return result;

Modified: python/trunk/Python/ast.c
==============================================================================
--- python/trunk/Python/ast.c	(original)
+++ python/trunk/Python/ast.c	Sat Aug 12 03:43:40 2006
@@ -2197,6 +2197,8 @@
             }
             else {
                 alias_ty a = alias_for_import_name(c, CHILD(n, 0));
+                if (!a)
+                    return NULL;
                 if (strcmp(STR(CHILD(n, 1)), "as") != 0) {
                     ast_error(n, "must use 'as' in import");
                     return NULL;

Modified: python/trunk/Python/symtable.c
==============================================================================
--- python/trunk/Python/symtable.c	(original)
+++ python/trunk/Python/symtable.c	Sat Aug 12 03:43:40 2006
@@ -915,6 +915,8 @@
 	PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
 		      ++st->st_cur->ste_tmpname);
 	tmp = PyString_InternFromString(tmpname);
+	if (!tmp)
+		return 0;
 	if (!symtable_add_def(st, tmp, DEF_LOCAL))
 		return 0;
 	Py_DECREF(tmp);
@@ -1323,8 +1325,11 @@
 	PyObject *name = (a->asname == NULL) ? a->name : a->asname;
 	const char *base = PyString_AS_STRING(name);
 	char *dot = strchr(base, '.');
-	if (dot)
+	if (dot) {
 		store_name = PyString_FromStringAndSize(base, dot - base);
+		if (!store_name)
+			return 0;
+	}
 	else {
 		store_name = name;
 		Py_INCREF(store_name);


More information about the Python-checkins mailing list