@@ -60,7 +60,7 @@ class Shape
6060 }
6161
6262 // Constructor that creates a shape from an array of dimension data.
63- Shape (int dimensions_count, const int32_t *dims_data) : _size(0 )
63+ Shape (int dimensions_count, const int32_t *dims_data) : _size(dimensions_count )
6464 {
6565 initStorage (dimensions_count);
6666 ReplaceWith (dimensions_count, dims_data);
@@ -205,6 +205,7 @@ class Shape
205205 // Replaces the current shape with a new one defined by dimensions_count and dims_data.
206206 inline void ReplaceWith (int dimensions_count, const int32_t *dims_data)
207207 {
208+ assert (dims_data != nullptr );
208209 Resize (dimensions_count);
209210 std::memcpy (DimsData (), dims_data, dimensions_count * sizeof (int32_t ));
210211 }
@@ -266,6 +267,7 @@ class Shape
266267 // Helper function: initialize dims_ storage based on the number of dimensions.
267268 inline void initStorage (int dimensions_count)
268269 {
270+ assert (dimensions_count > 0 );
269271 if (dimensions_count <= kMaxSmallSize )
270272 dims_ = std::array<int32_t , kMaxSmallSize >{};
271273 else
@@ -275,19 +277,18 @@ class Shape
275277 // For use only by ExtendedShape(), written to guarantee (return-value) copy
276278 // elision in C++17.
277279 // This creates a shape padded to the desired size with the specified value.
278- Shape (int new_shape_size, const Shape &shape, int pad_value) : _size(0 )
280+ Shape (int new_shape_size, const Shape &shape, int pad_value) : _size(new_shape_size )
279281 {
280282 assert (new_shape_size >= shape.DimensionsCount ());
281283 assert (new_shape_size <= kMaxSmallSize );
282- initStorage (new_shape_size);
284+ Resize (new_shape_size);
283285 const int size_increase = new_shape_size - shape.DimensionsCount ();
284286 for (int i = 0 ; i < size_increase; ++i)
285287 {
286288 SetDim (i, pad_value);
287289 }
288290 std::memcpy (DimsData () + size_increase, shape.DimsData (),
289291 sizeof (int32_t ) * shape.DimensionsCount ());
290- _size = new_shape_size;
291292 }
292293
293294 int32_t _size;
0 commit comments