mirror of
https://github.com/python/cpython.git
synced 2025-11-03 19:34:08 +00:00
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).
This commit is contained in:
parent
2a899c8b76
commit
6f5ff3f3eb
8 changed files with 28 additions and 3 deletions
|
|
@ -23,4 +23,8 @@ in addition to any analysis.
|
||||||
False positives were also annotated so that the comments can
|
False positives were also annotated so that the comments can
|
||||||
be reviewed and reversed if the analysis was incorrect.
|
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@python.org for more information.
|
Contact python-dev@python.org for more information.
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,8 @@ escape_encode(PyObject *self,
|
||||||
buf = PyString_AS_STRING (str);
|
buf = PyString_AS_STRING (str);
|
||||||
len = PyString_GET_SIZE (str);
|
len = PyString_GET_SIZE (str);
|
||||||
memmove(buf, buf+1, len-2);
|
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));
|
return codec_tuple(str, PyString_Size(str));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -809,7 +809,7 @@ element_findtext(ElementObject* self, PyObject* args)
|
||||||
PyObject* text = element_get_text(item);
|
PyObject* text = element_get_text(item);
|
||||||
if (text == Py_None)
|
if (text == Py_None)
|
||||||
return PyString_FromString("");
|
return PyString_FromString("");
|
||||||
Py_INCREF(text);
|
Py_XINCREF(text);
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -313,6 +313,11 @@ unpack_string(LogReaderObject *self, PyObject **pvalue)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
buf = (char *)malloc(len);
|
buf = (char *)malloc(len);
|
||||||
|
if (!buf) {
|
||||||
|
PyErr_NoMemory();
|
||||||
|
return ERR_EXCEPTION;
|
||||||
|
}
|
||||||
|
|
||||||
for (i=0; i < len; i++) {
|
for (i=0; i < len; i++) {
|
||||||
ch = fgetc(self->logfp);
|
ch = fgetc(self->logfp);
|
||||||
buf[i] = ch;
|
buf[i] = ch;
|
||||||
|
|
|
||||||
|
|
@ -702,6 +702,8 @@ array_ass_slice(arrayobject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v)
|
||||||
/* Special case "a[i:j] = a" -- copy b first */
|
/* Special case "a[i:j] = a" -- copy b first */
|
||||||
int ret;
|
int ret;
|
||||||
v = array_slice(b, 0, n);
|
v = array_slice(b, 0, n);
|
||||||
|
if (!v)
|
||||||
|
return -1;
|
||||||
ret = array_ass_slice(a, ilow, ihigh, v);
|
ret = array_ass_slice(a, ilow, ihigh, v);
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -1708,6 +1710,8 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value)
|
||||||
if (self == av) {
|
if (self == av) {
|
||||||
value = array_slice(av, 0, av->ob_size);
|
value = array_slice(av, 0, av->ob_size);
|
||||||
av = (arrayobject*)value;
|
av = (arrayobject*)value;
|
||||||
|
if (!av)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_INCREF(value);
|
Py_INCREF(value);
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,8 @@ structseq_contains(PyStructSequence *obj, PyObject *o)
|
||||||
PyObject *tup;
|
PyObject *tup;
|
||||||
int result;
|
int result;
|
||||||
tup = make_tuple(obj);
|
tup = make_tuple(obj);
|
||||||
|
if (!tup)
|
||||||
|
return -1;
|
||||||
result = PySequence_Contains(tup, o);
|
result = PySequence_Contains(tup, o);
|
||||||
Py_DECREF(tup);
|
Py_DECREF(tup);
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -226,6 +228,8 @@ structseq_hash(PyObject *obj)
|
||||||
PyObject *tup;
|
PyObject *tup;
|
||||||
long result;
|
long result;
|
||||||
tup = make_tuple((PyStructSequence*) obj);
|
tup = make_tuple((PyStructSequence*) obj);
|
||||||
|
if (!tup)
|
||||||
|
return -1;
|
||||||
result = PyObject_Hash(tup);
|
result = PyObject_Hash(tup);
|
||||||
Py_DECREF(tup);
|
Py_DECREF(tup);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -2197,6 +2197,8 @@ alias_for_import_name(struct compiling *c, const node *n)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
alias_ty a = alias_for_import_name(c, CHILD(n, 0));
|
alias_ty a = alias_for_import_name(c, CHILD(n, 0));
|
||||||
|
if (!a)
|
||||||
|
return NULL;
|
||||||
if (strcmp(STR(CHILD(n, 1)), "as") != 0) {
|
if (strcmp(STR(CHILD(n, 1)), "as") != 0) {
|
||||||
ast_error(n, "must use 'as' in import");
|
ast_error(n, "must use 'as' in import");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -915,6 +915,8 @@ symtable_new_tmpname(struct symtable *st)
|
||||||
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
|
PyOS_snprintf(tmpname, sizeof(tmpname), "_[%d]",
|
||||||
++st->st_cur->ste_tmpname);
|
++st->st_cur->ste_tmpname);
|
||||||
tmp = PyString_InternFromString(tmpname);
|
tmp = PyString_InternFromString(tmpname);
|
||||||
|
if (!tmp)
|
||||||
|
return 0;
|
||||||
if (!symtable_add_def(st, tmp, DEF_LOCAL))
|
if (!symtable_add_def(st, tmp, DEF_LOCAL))
|
||||||
return 0;
|
return 0;
|
||||||
Py_DECREF(tmp);
|
Py_DECREF(tmp);
|
||||||
|
|
@ -1323,8 +1325,11 @@ symtable_visit_alias(struct symtable *st, alias_ty a)
|
||||||
PyObject *name = (a->asname == NULL) ? a->name : a->asname;
|
PyObject *name = (a->asname == NULL) ? a->name : a->asname;
|
||||||
const char *base = PyString_AS_STRING(name);
|
const char *base = PyString_AS_STRING(name);
|
||||||
char *dot = strchr(base, '.');
|
char *dot = strchr(base, '.');
|
||||||
if (dot)
|
if (dot) {
|
||||||
store_name = PyString_FromStringAndSize(base, dot - base);
|
store_name = PyString_FromStringAndSize(base, dot - base);
|
||||||
|
if (!store_name)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
store_name = name;
|
store_name = name;
|
||||||
Py_INCREF(store_name);
|
Py_INCREF(store_name);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue