diff --git a/matlab.h b/matlab.h index 58b6dda..253ae74 100644 --- a/matlab.h +++ b/matlab.h @@ -436,8 +436,10 @@ MatrixView unwrapMatrixView(const mxArray* array) { if (mxIsDouble(array)==false || mxIsComplex(array) || mxIsSparse(array)) error("unwrapMatrixView: not a full real double matrix"); const mwSize rows = mxGetM(array), cols = mxGetN(array); - if (rows > static_cast(std::numeric_limits::max()) || - cols > static_cast(std::numeric_limits::max())) { + const auto maxIndex = + static_cast((std::numeric_limits::max)()); + if (static_cast(rows) > maxIndex || + static_cast(cols) > maxIndex) { error("unwrapMatrixView: matrix dimensions exceed Eigen::Index"); } const Eigen::Index m = static_cast(rows); diff --git a/tests/test_matlab_wrapper.py b/tests/test_matlab_wrapper.py index 37eb692..3b98442 100644 --- a/tests/test_matlab_wrapper.py +++ b/tests/test_matlab_wrapper.py @@ -115,6 +115,7 @@ def test_matrix_view_arguments(self): self.assertIn('unwrapMatrixView', header_content) self.assertIn('mxIsSparse(array)', header_content) self.assertIn('mwSize rows', header_content) + self.assertIn('static_cast(rows)', header_content) self.assertIn('Eigen::Index m', header_content) self.assertIn('Stride(m, 1)', header_content)