mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-11 17:00:34 +00:00
Fix SEGV to create empty shaped numpy array (#1371)
Fix a segfault when creating a 0-dimension, c-strides array.
This commit is contained in:
committed by
Jason Rhinelander
parent
4b874616b2
commit
5ef1af138d
@@ -758,8 +758,9 @@ protected:
|
||||
static std::vector<ssize_t> c_strides(const std::vector<ssize_t> &shape, ssize_t itemsize) {
|
||||
auto ndim = shape.size();
|
||||
std::vector<ssize_t> strides(ndim, itemsize);
|
||||
for (size_t i = ndim - 1; i > 0; --i)
|
||||
strides[i - 1] = strides[i] * shape[i];
|
||||
if (ndim > 0)
|
||||
for (size_t i = ndim - 1; i > 0; --i)
|
||||
strides[i - 1] = strides[i] * shape[i];
|
||||
return strides;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user