diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-09-06 07:42:29 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-09-06 07:42:29 (GMT) |
commit | 527a2400fb236bb4ab9fa81ad90d932bab6da071 (patch) | |
tree | 79949ef27aa45b4b009b550fc85004b2735b1468 /Modules/_testbuffer.c | |
parent | b2a61e1ead72a89d21a0bd84930dbb7a28be3793 (diff) | |
download | cpython-527a2400fb236bb4ab9fa81ad90d932bab6da071.zip cpython-527a2400fb236bb4ab9fa81ad90d932bab6da071.tar.gz cpython-527a2400fb236bb4ab9fa81ad90d932bab6da071.tar.bz2 |
_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.
Diffstat (limited to 'Modules/_testbuffer.c')
-rw-r--r-- | Modules/_testbuffer.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/Modules/_testbuffer.c b/Modules/_testbuffer.c index 87ada0a..316666e 100644 --- a/Modules/_testbuffer.c +++ b/Modules/_testbuffer.c @@ -16,6 +16,7 @@ PyObject *calcsize = NULL; 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 @@ static int 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; |