Skip to content

Commit 527a240

Browse files
committed
_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.
1 parent b2a61e1 commit 527a240

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

Modules/_testbuffer.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ PyObject *calcsize = NULL;
1616
static const char *simple_fmt = "B";
1717
PyObject *simple_format = NULL;
1818
#define SIMPLE_FORMAT(fmt) (fmt == NULL || strcmp(fmt, "B") == 0)
19+
#define FIX_FORMAT(fmt) (fmt == NULL ? "B" : fmt)
1920

2021

2122
/**************************************************************************/
@@ -513,10 +514,8 @@ static int
513514
cmp_structure(Py_buffer *dest, Py_buffer *src)
514515
{
515516
Py_ssize_t i;
516-
int same_fmt = ((dest->format == NULL && src->format == NULL) || \
517-
(strcmp(dest->format, src->format) == 0));
518517

519-
if (!same_fmt ||
518+
if (strcmp(FIX_FORMAT(dest->format), FIX_FORMAT(src->format)) != 0 ||
520519
dest->itemsize != src->itemsize ||
521520
dest->ndim != src->ndim)
522521
return -1;

0 commit comments

Comments
 (0)