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.

This commit is contained in:
vanhoucke 2015-06-19 15:53:30 +00:00
parent e4ed2566d5
commit 8d4d85161e

View File

@ -208,8 +208,10 @@ class CompressedStorage
Index* newIndices = new Index[size];
size_t copySize = (std::min)(size, m_size);
// copy
internal::smart_copy(m_values, m_values+copySize, newValues);
internal::smart_copy(m_indices, m_indices+copySize, newIndices);
if (copySize>0) {
internal::smart_copy(m_values, m_values+copySize, newValues);
internal::smart_copy(m_indices, m_indices+copySize, newIndices);
}
// delete old stuff
delete[] m_values;
delete[] m_indices;