From 613a5c675957bf7441ad5a39411fa9cecf2f0452 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jouni=20K=2E=20Seppa=CC=88nen?= Date: Sat, 19 Apr 2014 18:48:19 +0300 Subject: [PATCH] Avoid a null-pointer dereference in _tri.cpp Found using the clang static analyzer: if PyArray_ContiguousFromObject returns NULL, PyArray_NDIM(x) causes a null-pointer dereference. --- lib/matplotlib/tri/_tri.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tri/_tri.cpp b/lib/matplotlib/tri/_tri.cpp index 8dbe107e5ed7..d7d676032912 100644 --- a/lib/matplotlib/tri/_tri.cpp +++ b/lib/matplotlib/tri/_tri.cpp @@ -1371,7 +1371,7 @@ TrapezoidMapTriFinder::find_many(const Py::Tuple& args) PyArrayObject* y = (PyArrayObject*)PyArray_ContiguousFromObject( args[1].ptr(), PyArray_DOUBLE, 0, 0); bool ok = (x != 0 && y != 0 && PyArray_NDIM(x) == PyArray_NDIM(y)); - int ndim = PyArray_NDIM(x); + int ndim = x == 0 ? 0 : PyArray_NDIM(x); for (int i = 0; ok && i < ndim; ++i) ok = (PyArray_DIM(x,i) == PyArray_DIM(y,i));