From 4cc0c961f3fdec9d47a9cc81ff85bbe340945478 Mon Sep 17 00:00:00 2001 From: vanhoucke Date: Fri, 19 Jun 2015 15:46:46 +0000 Subject: [PATCH 1/2] Fix undefined behavior. --- unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h b/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h index 108c45a32..1de6ce3b4 100644 --- a/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h +++ b/unsupported/Eigen/CXX11/src/Tensor/TensorIntDiv.h @@ -58,7 +58,7 @@ struct TensorIntDivisor { EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE TensorIntDivisor(const T divider) { const int N = 32; eigen_assert(divider > 0); - eigen_assert(divider <= (1<<(N-1)) - 1); + eigen_assert(divider <= (1U<<(N-1)) - 1); // fast ln2 const int leading_zeros = count_leading_zeros(divider); From 368ea234066a14d9427fd59ab064e2c6d96ba723 Mon Sep 17 00:00:00 2001 From: vanhoucke Date: Fri, 19 Jun 2015 15:53:30 +0000 Subject: [PATCH 2/2] Fix undefined behavior. When resizing a default-constructed SparseArray, we end up calling memcpy(ptr, 0, 0), which is technically UB and gets caught by static analysis. --- Eigen/src/SparseCore/CompressedStorage.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Eigen/src/SparseCore/CompressedStorage.h b/Eigen/src/SparseCore/CompressedStorage.h index 5af270bc5..d667944ce 100644 --- a/Eigen/src/SparseCore/CompressedStorage.h +++ b/Eigen/src/SparseCore/CompressedStorage.h @@ -229,8 +229,10 @@ class CompressedStorage internal::scoped_array newValues(size); internal::scoped_array newIndices(size); Index copySize = (std::min)(size, m_size); - internal::smart_copy(m_values, m_values+copySize, newValues.ptr()); - internal::smart_copy(m_indices, m_indices+copySize, newIndices.ptr()); + if (copySize>0) { + internal::smart_copy(m_values, m_values+copySize, newValues.ptr()); + internal::smart_copy(m_indices, m_indices+copySize, newIndices.ptr()); + } std::swap(m_values,newValues.ptr()); std::swap(m_indices,newIndices.ptr()); m_allocatedSize = size;