Skip to content

Commit 65a4295

Browse files
committed
Add some nullptr checks (#160)
1 parent 2230e5b commit 65a4295

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

onnxruntime/contrib_ops/cpu/range.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ static Status ComputeRange(OpKernelContext* ctx) {
4848
}
4949

5050
Status Range::Compute(OpKernelContext* ctx) const {
51-
auto data_type = ctx->Input<Tensor>(0)->DataType();
51+
auto input_tensor = ctx->Input<Tensor>(0);
52+
if (input_tensor == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch");
53+
auto data_type = input_tensor->DataType();
5254
if (data_type == DataTypeImpl::GetType<int32_t>()) {
5355
return ComputeRange<int32_t>(ctx);
5456
}

onnxruntime/contrib_ops/cpu/string_normalizer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ Status StringNormalizer::Compute(OpKernelContext* ctx) const {
207207
using namespace string_normalizer;
208208

209209
auto X = ctx->Input<Tensor>(0);
210+
if (X == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch");
210211
auto& input_dims = X->Shape().GetDims();
211212

212213
size_t N = 0;

onnxruntime/contrib_ops/cpu/tokenizer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ Status Tokenizer::SeparatorTokenize(OpKernelContext* ctx,
450450
Status Tokenizer::Compute(OpKernelContext* ctx) const {
451451
// Get input buffer ptr
452452
auto X = ctx->Input<Tensor>(0);
453+
if (X == nullptr) return Status(common::ONNXRUNTIME, common::FAIL, "input count mismatch");
453454
if (X->DataType() != DataTypeImpl::GetType<std::string>()) {
454455
return Status(common::ONNXRUNTIME, common::INVALID_ARGUMENT,
455456
"tensor(string) expected as input");

onnxruntime/core/providers/cpu/tensor/eye_like.cc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,18 @@ Status EyeLike::Compute(OpKernelContext* context) const {
3333
auto output_tensor_dtype = has_dtype_ ? static_cast<onnx::TensorProto::DataType>(dtype_) : utils::GetTensorProtoType(*T1);
3434
switch (output_tensor_dtype) {
3535
case onnx::TensorProto_DataType_FLOAT:
36-
return ComputeImpl<float>(context);
36+
return ComputeImpl<float>(context, T1);
3737
case onnx::TensorProto_DataType_INT64:
38-
return ComputeImpl<int64_t>(context);
38+
return ComputeImpl<int64_t>(context, T1);
3939
case onnx::TensorProto_DataType_UINT64:
40-
return ComputeImpl<uint64_t>(context);
40+
return ComputeImpl<uint64_t>(context, T1);
4141
default:
4242
ONNXRUNTIME_THROW("Unsupported 'dtype' value: ", output_tensor_dtype);
4343
}
4444
}
4545

4646
template <typename T>
47-
Status EyeLike::ComputeImpl(OpKernelContext* context) const {
48-
const Tensor* T1 = context->Input<Tensor>(0);
47+
Status EyeLike::ComputeImpl(OpKernelContext* context, const Tensor* T1) const {
4948
const std::vector<int64_t>& input_dims = T1->Shape().GetDims();
5049
if (input_dims.size() != 2) {
5150
return Status(ONNXRUNTIME, INVALID_ARGUMENT, "EyeLike : Input tensor dimension is not 2");

onnxruntime/core/providers/cpu/tensor/eye_like.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class EyeLike final : public OpKernel {
2222

2323
private:
2424
template <typename T>
25-
Status ComputeImpl(OpKernelContext* context) const;
25+
Status ComputeImpl(OpKernelContext* context, const Tensor* T1) const;
2626

2727
bool has_dtype_;
2828
int64_t dtype_;

0 commit comments

Comments
 (0)