Skip to content

Commit 8d475ad

Browse files
author
neal.norwitz
committed
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). git-svn-id: http://svn.python.org/projects/python/trunk@51218 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 41234c4 commit 8d475ad

File tree

8 files changed

+28
-3
lines changed

8 files changed

+28
-3
lines changed

Misc/README.klocwork

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ in addition to any analysis.
2323
False positives were also annotated so that the comments can
2424
be reviewed and reversed if the analysis was incorrect.
2525

26+
A second run was performed on 10-Aug-2006. The tool was tuned to remove
27+
some false positives and perform some additional checks. ~150 new
28+
warnings were produced, primarily related to dereferencing NULL pointers.
29+
2630
Contact python-dev@python.org for more information.

Modules/_codecsmodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ escape_encode(PyObject *self,
192192
buf = PyString_AS_STRING (str);
193193
len = PyString_GET_SIZE (str);
194194
memmove(buf, buf+1, len-2);
195-
_PyString_Resize(&str, len-2);
195+
if (_PyString_Resize(&str, len-2) < 0)
196+
return NULL;
196197

197198
return codec_tuple(str, PyString_Size(str));
198199
}

Modules/_elementtree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ element_findtext(ElementObject* self, PyObject* args)
809809
PyObject* text = element_get_text(item);
810810
if (text == Py_None)
811811
return PyString_FromString("");
812-
Py_INCREF(text);
812+
Py_XINCREF(text);
813813
return text;
814814
}
815815
}

Modules/_hotshot.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ unpack_string(LogReaderObject *self, PyObject **pvalue)
313313
return err;
314314

315315
buf = (char *)malloc(len);
316+
if (!buf) {
317+
PyErr_NoMemory();
318+
return ERR_EXCEPTION;
319+
}
320+
316321
for (i=0; i < len; i++) {
317322
ch = fgetc(self->logfp);
318323
buf[i] = ch;

Modules/arraymodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,8 @@ array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
702702
/* Special case "a[i:j] = a" -- copy b first */
703703
int ret;
704704
v = array_slice(b, 0, n);
705+
if (!v)
706+
return -1;
705707
ret = array_ass_slice(a, ilow, ihigh, v);
706708
Py_DECREF(v);
707709
return ret;
@@ -1708,6 +1710,8 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
17081710
if (self == av) {
17091711
value = array_slice(av, 0, av->ob_size);
17101712
av = (arrayobject*)value;
1713+
if (!av)
1714+
return -1;
17111715
}
17121716
else {
17131717
Py_INCREF(value);

Objects/structseq.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ structseq_contains(PyStructSequence *obj, PyObject *o)
215215
PyObject *tup;
216216
int result;
217217
tup = make_tuple(obj);
218+
if (!tup)
219+
return -1;
218220
result = PySequence_Contains(tup, o);
219221
Py_DECREF(tup);
220222
return result;
@@ -226,6 +228,8 @@ structseq_hash(PyObject *obj)
226228
PyObject *tup;
227229
long result;
228230
tup = make_tuple((PyStructSequence*) obj);
231+
if (!tup)
232+
return -1;
229233
result = PyObject_Hash(tup);
230234
Py_DECREF(tup);
231235
return result;

Python/ast.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,6 +2197,8 @@ alias_for_import_name(struct compiling *c, const node *n)
21972197
}
21982198
else {
21992199
alias_ty a = alias_for_import_name(c, CHILD(n, 0));
2200+
if (!a)
2201+
return NULL;
22002202
if (strcmp(STR(CHILD(n, 1)), "as") != 0) {
22012203
ast_error(n, "must use 'as' in import");
22022204
return NULL;

Python/symtable.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,8 @@ symtable_new_tmpname(struct symtable *st)
915915
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
916916
++st->st_cur->ste_tmpname);
917917
tmp = PyString_InternFromString(tmpname);
918+
if (!tmp)
919+
return 0;
918920
if (!symtable_add_def(st, tmp, DEF_LOCAL))
919921
return 0;
920922
Py_DECREF(tmp);
@@ -1323,8 +1325,11 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
13231325
PyObject *name = (a->asname == NULL) ? a->name : a->asname;
13241326
const char *base = PyString_AS_STRING(name);
13251327
char *dot = strchr(base, '.');
1326-
if (dot)
1328+
if (dot) {
13271329
store_name = PyString_FromStringAndSize(base, dot - base);
1330+
if (!store_name)
1331+
return 0;
1332+
}
13281333
else {
13291334
store_name = name;
13301335
Py_INCREF(store_name);

0 commit comments

Comments
 (0)