From 2879ee8bd2cc7bacf556560c48ead263ed94a047 Mon Sep 17 00:00:00 2001 From: Changming Sun Date: Sun, 21 Apr 2019 16:45:03 -0700 Subject: [PATCH] Fix a few warnings (#762) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix warning in tensor_type_and_shape.cc tensor_type_and_shape.cc:139:18: error: ‘out’ may be used uninitialized in this function [-Werror=maybe-uninitialized] * fix warnings --- onnxruntime/core/framework/tensor_type_and_shape.cc | 2 +- onnxruntime/core/providers/cpu/tensor/unsqueeze.cc | 6 +++--- onnxruntime/core/providers/cpu/tensor/unsqueeze.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/onnxruntime/core/framework/tensor_type_and_shape.cc b/onnxruntime/core/framework/tensor_type_and_shape.cc index e27adcbf6f..ea17763bac 100644 --- a/onnxruntime/core/framework/tensor_type_and_shape.cc +++ b/onnxruntime/core/framework/tensor_type_and_shape.cc @@ -136,7 +136,7 @@ ORT_API(enum ONNXType, OrtGetValueType, _In_ const OrtValue* value) { try { auto v = reinterpret_cast(value); onnxruntime::MLDataType type = v->Type(); - OrtTypeInfo* out; + OrtTypeInfo* out = nullptr; OrtStatus* ptr = OrtTypeInfo::FromDataTypeImpl(type, nullptr, nullptr, &out); if (ptr != nullptr) { OrtReleaseStatus(ptr); diff --git a/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc b/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc index 997210e49b..96a98fc4f1 100644 --- a/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc +++ b/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc @@ -22,11 +22,11 @@ Status UnsqueezeBase::PrepareCompute(OpKernelContext* ctx, Prepare& p) const { // New dimension count is the current dimensions + the number of entries in axes_ // Initialize output_dims to 0 in each axis initially - std::vector output_dims(axes_.size() + input_tensor.Shape().GetDims().size(), 0); + std::vector output_dims(axes_.size() + input_tensor.Shape().NumDimensions(), 0); // Set all axes_ indices to 1 in output_dims and check for duplicates - for (size_t axis : axes_) { - if (axis >= output_dims.size()) + for (int64_t axis : axes_) { + if (axis < 0 || axis >= static_cast(output_dims.size())) return Status(ONNXRUNTIME, INVALID_ARGUMENT, "'axes' has an out of range axis"); if (output_dims[axis] != 0) return Status(ONNXRUNTIME, INVALID_ARGUMENT, "'axes' has a duplicate axis"); diff --git a/onnxruntime/core/providers/cpu/tensor/unsqueeze.h b/onnxruntime/core/providers/cpu/tensor/unsqueeze.h index bbe42d9868..3ab5d8d0f8 100644 --- a/onnxruntime/core/providers/cpu/tensor/unsqueeze.h +++ b/onnxruntime/core/providers/cpu/tensor/unsqueeze.h @@ -15,8 +15,8 @@ class UnsqueezeBase { } struct Prepare { - const Tensor* input_tensor; - Tensor* output_tensor; + const Tensor* input_tensor = nullptr; + Tensor* output_tensor = nullptr; }; Status PrepareCompute(OpKernelContext* context, Prepare& p) const;