Skip to content

Commit d1e34f5

Browse files
committed
If shape pointer is null, warn and don't allocate.
1 parent ed269dd commit d1e34f5

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/axom/sidre/core/View.cpp

+15-8
Original file line numberDiff line numberDiff line change
@@ -133,20 +133,27 @@ View* View::allocate(TypeID type, int ndims, const IndexType* shape, int allocID
133133
SIDRE_VIEW_LOG_PREPEND
134134
<< "Could not allocate: Data type was 'NO_TYPE_ID'.");
135135

136+
SLIC_CHECK_MSG(shape != nullptr,
137+
SIDRE_VIEW_LOG_PREPEND
138+
<< "Could not allocate: specified shape is nullptr.");
139+
136140
IndexType num_elems = 1;
137-
for(int d = 0; d < ndims; ++d)
141+
if(shape != nullptr)
138142
{
139-
SLIC_CHECK_MSG(
140-
shape[d] > 0,
141-
SIDRE_VIEW_LOG_PREPEND << "Could not allocate: shape is non-positive.");
142-
num_elems *= shape[d];
143-
if(num_elems <= 0)
143+
for(int d = 0; d < ndims; ++d)
144144
{
145-
break;
145+
SLIC_CHECK_MSG(
146+
shape[d] > 0,
147+
SIDRE_VIEW_LOG_PREPEND << "Could not allocate: shape is non-positive.");
148+
num_elems *= shape[d];
149+
if(num_elems <= 0)
150+
{
151+
break;
152+
}
146153
}
147154
}
148155

149-
if(ndims > 0 && num_elems > 0 && type != NO_TYPE_ID)
156+
if(ndims > 0 && shape != nullptr && num_elems > 0 && type != NO_TYPE_ID)
150157
{
151158
describe(type, ndims, shape);
152159
allocate(allocID);

src/axom/sidre/core/View.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ class View
372372
*
373373
* \note The allocate() method (above) describes conditions where View
374374
* allocation is allowed. If the conditions are not met,
375-
* type is NO_TYPE_ID, or ndims < 0, or any element of shape < 0,
376-
* this method does nothing.
375+
* type is NO_TYPE_ID, or ndims < 0, or shape is nullptr,
376+
* or any element of shape < 0, this method does nothing.
377377
*
378378
* \return pointer to this View object.
379379
*/

0 commit comments

Comments
 (0)