diff --git a/onnxruntime/core/framework/tensor.cc b/onnxruntime/core/framework/tensor.cc index 4463ec7145..d0085c0fe6 100644 --- a/onnxruntime/core/framework/tensor.cc +++ b/onnxruntime/core/framework/tensor.cc @@ -21,7 +21,9 @@ Tensor::Tensor(MLDataType p_type, const TensorShape& shape, std::shared_ptr(shape_size) >= std::numeric_limits::max()) ORT_THROW("shape.Size() must >=0"); - void* p_data = allocator->AllocArray(static_cast(shape_size), p_type->Size()); + void* p_data = nullptr; + if(shape_size > 0) + p_data = allocator->AllocArray(static_cast(shape_size), p_type->Size()); Init(p_type, shape, p_data, allocator, offset); }