[Python-checkins] cpython: _testbuffer.c: In all current use cases of cmp_structure() dest->format and
stefan.krah
python-checkins at python.org
Thu Sep 6 09:49:19 CEST 2012
http://hg.python.org/cpython/rev/7c007110d952
changeset: 78859:7c007110d952
user: Stefan Krah <skrah at bytereef.org>
date: Thu Sep 06 09:42:29 2012 +0200
summary:
_testbuffer.c: In all current use cases of cmp_structure() dest->format and
src->format are either both NULL or both non-NULL. However, it is safer to
generalize the function. Found by Coverity.
files:
Modules/_testbuffer.c | 7 +++----
1 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c
--- a/Modules/_testbuffer.c
+++ b/Modules/_testbuffer.c
@@ -16,6 +16,7 @@
static const char *simple_fmt = "B";
PyObject *simple_format = NULL;
#define SIMPLE_FORMAT(fmt) (fmt == NULL || strcmp(fmt, "B") == 0)
+#define FIX_FORMAT(fmt) (fmt == NULL ? "B" : fmt)
/**************************************************************************/
@@ -513,10 +514,8 @@
cmp_structure(Py_buffer *dest, Py_buffer *src)
{
Py_ssize_t i;
- int same_fmt = ((dest->format == NULL && src->format == NULL) || \
- (strcmp(dest->format, src->format) == 0));
-
- if (!same_fmt ||
+
+ if (strcmp(FIX_FORMAT(dest->format), FIX_FORMAT(src->format)) != 0 ||
dest->itemsize != src->itemsize ||
dest->ndim != src->ndim)
return -1;
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list