From 76b31d6ce2a1fade1746f340cee32ca0e9bb4dfa Mon Sep 17 00:00:00 2001 From: RandySheriffH <48490400+RandySheriffH@users.noreply.github.com> Date: Thu, 16 Jul 2020 10:20:34 -0700 Subject: [PATCH] fix xcode alerts (#4470) * fix xcode alerts * fix comment * fix comments * update text * fix comments * fix comments * remove checks on context Co-authored-by: Randy Co-authored-by: Randy Co-authored-by: Tracy Sharpe --- onnxruntime/contrib_ops/cpu/crop.h | 7 ++----- onnxruntime/core/common/threadpool.cc | 1 - onnxruntime/core/framework/error_code.cc | 2 +- onnxruntime/core/framework/kernel_registry.cc | 3 +-- onnxruntime/core/framework/tensorprotoutils.cc | 2 +- onnxruntime/core/mlas/lib/pooling.cpp | 4 ++++ onnxruntime/core/platform/posix/env.cc | 12 ++++++------ onnxruntime/core/providers/cpu/math/cumsum.cc | 2 +- .../core/providers/cpu/reduction/reduction_ops.cc | 4 ++++ onnxruntime/core/providers/cpu/tensor/unsqueeze.cc | 3 +-- onnxruntime/test/onnx/tensorprotoutils.cc | 2 +- 11 files changed, 22 insertions(+), 20 deletions(-) diff --git a/onnxruntime/contrib_ops/cpu/crop.h b/onnxruntime/contrib_ops/cpu/crop.h index 7d6e2566a2..d06be5645c 100644 --- a/onnxruntime/contrib_ops/cpu/crop.h +++ b/onnxruntime/contrib_ops/cpu/crop.h @@ -48,13 +48,10 @@ class CropBase { return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, "Input's width (", W, ") needs to be greater than or equal to the leftBorder (", leftBorder, ") + rightBorder (", rightBorder, ")"); } - int64_t bottomLimit = H - bottomBorder; - int64_t rightLimit = W - rightBorder; - // scale = (height, width) if (!scale_.empty()) { - bottomLimit = topBorder + scale_[0]; - rightLimit = leftBorder + scale_[1]; + int64_t bottomLimit = topBorder + scale_[0]; + int64_t rightLimit = leftBorder + scale_[1]; if (H < bottomLimit) { return ORT_MAKE_STATUS(ONNXRUNTIME, INVALID_ARGUMENT, diff --git a/onnxruntime/core/common/threadpool.cc b/onnxruntime/core/common/threadpool.cc index 3e053ce9f4..374a882dc7 100644 --- a/onnxruntime/core/common/threadpool.cc +++ b/onnxruntime/core/common/threadpool.cc @@ -312,7 +312,6 @@ static ptrdiff_t CalculateParallelForBlock(const ptrdiff_t n, const Eigen::Tenso if (coarser_efficiency + 0.01 >= max_efficiency) { // Taking it. block_size = coarser_block_size; - block_count = coarser_block_count; if (max_efficiency < coarser_efficiency) { max_efficiency = coarser_efficiency; } diff --git a/onnxruntime/core/framework/error_code.cc b/onnxruntime/core/framework/error_code.cc index 4c6f73f915..02d5c4a1d3 100644 --- a/onnxruntime/core/framework/error_code.cc +++ b/onnxruntime/core/framework/error_code.cc @@ -23,7 +23,7 @@ struct OrtStatus { _Check_return_ _Ret_notnull_ OrtStatus* ORT_API_CALL OrtApis::CreateStatus(OrtErrorCode code, _In_z_ const char* msg) NO_EXCEPTION { assert(!(code == 0 && msg != nullptr)); - SafeInt clen(strlen(msg)); + SafeInt clen(nullptr == msg ? 0 : strlen(msg)); OrtStatus* p = reinterpret_cast(::malloc(sizeof(OrtStatus) + clen)); if (p == nullptr) return nullptr; // OOM. What we can do here? abort()? p->code = code; diff --git a/onnxruntime/core/framework/kernel_registry.cc b/onnxruntime/core/framework/kernel_registry.cc index 081031c343..844c2a0d9d 100644 --- a/onnxruntime/core/framework/kernel_registry.cc +++ b/onnxruntime/core/framework/kernel_registry.cc @@ -233,9 +233,8 @@ Status KernelRegistry::TryCreateKernel(const onnxruntime::Node& node, const FuncManager& funcs_mgr, const DataTransferManager& data_transfer_mgr, /*out*/ std::unique_ptr& op_kernel) const { - const KernelCreateInfo* kernel_create_info; + const KernelCreateInfo* kernel_create_info = nullptr; ORT_RETURN_IF_ERROR(TryFindKernel(node, execution_provider.Type(), &kernel_create_info)); - OpKernelInfo kernel_info(node, *kernel_create_info->kernel_def, execution_provider, diff --git a/onnxruntime/core/framework/tensorprotoutils.cc b/onnxruntime/core/framework/tensorprotoutils.cc index 4021be3c2d..d7346fb702 100644 --- a/onnxruntime/core/framework/tensorprotoutils.cc +++ b/onnxruntime/core/framework/tensorprotoutils.cc @@ -698,7 +698,7 @@ common::Status SparseTensorProtoToDenseTensorProto(const ONNX_NAMESPACE::SparseT auto dims = gsl::make_span(dense.dims().data(), dense.dims().size()); // need to read in sparse data first as it could be in a type specific field, in raw data, or in external data - size_t sparse_bytes; + size_t sparse_bytes = 0; ORT_RETURN_IF_ERROR(GetSizeInBytesFromTensorProto<0>(sparse_values, &sparse_bytes)); if (type != TensorProto_DataType_STRING) { diff --git a/onnxruntime/core/mlas/lib/pooling.cpp b/onnxruntime/core/mlas/lib/pooling.cpp index 805b6e243f..dfe87578d6 100644 --- a/onnxruntime/core/mlas/lib/pooling.cpp +++ b/onnxruntime/core/mlas/lib/pooling.cpp @@ -1196,6 +1196,10 @@ Return Value: bool AllPaddingIsZero = true; bool AllKernelsAreSmall = true; + if (Dimensions > 3) { + throw std::runtime_error("bad dimensions"); + } + for (size_t dim = 0; dim < Dimensions; dim++) { WorkBlock.InputShape[dim] = size_t(InputShape[dim]); diff --git a/onnxruntime/core/platform/posix/env.cc b/onnxruntime/core/platform/posix/env.cc index 35f7b1db40..3db54352c7 100644 --- a/onnxruntime/core/platform/posix/env.cc +++ b/onnxruntime/core/platform/posix/env.cc @@ -423,9 +423,9 @@ class PosixEnv : public Env { } common::Status LoadDynamicLibrary(const std::string& library_filename, void** handle) const override { - char* error_str = dlerror(); // clear any old error_str + dlerror(); // clear any old error_str *handle = dlopen(library_filename.c_str(), RTLD_NOW | RTLD_LOCAL); - error_str = dlerror(); + char* error_str = dlerror(); if (!*handle) { return common::Status(common::ONNXRUNTIME, common::FAIL, "Failed to load library " + library_filename + " with error: " + error_str); @@ -437,9 +437,9 @@ class PosixEnv : public Env { if (!handle) { return common::Status(common::ONNXRUNTIME, common::FAIL, "Got null library handle"); } - char* error_str = dlerror(); // clear any old error_str + dlerror(); // clear any old error_str int retval = dlclose(handle); - error_str = dlerror(); + char* error_str = dlerror(); if (retval != 0) { return common::Status(common::ONNXRUNTIME, common::FAIL, "Failed to unload library with error: " + std::string(error_str)); @@ -448,9 +448,9 @@ class PosixEnv : public Env { } common::Status GetSymbolFromLibrary(void* handle, const std::string& symbol_name, void** symbol) const override { - char* error_str = dlerror(); // clear any old error str + dlerror(); // clear any old error str *symbol = dlsym(handle, symbol_name.c_str()); - error_str = dlerror(); + char* error_str = dlerror(); if (error_str) { return common::Status(common::ONNXRUNTIME, common::FAIL, "Failed to get symbol " + symbol_name + " with error: " + error_str); diff --git a/onnxruntime/core/providers/cpu/math/cumsum.cc b/onnxruntime/core/providers/cpu/math/cumsum.cc index 9370b6942b..0371d18ddc 100644 --- a/onnxruntime/core/providers/cpu/math/cumsum.cc +++ b/onnxruntime/core/providers/cpu/math/cumsum.cc @@ -144,7 +144,7 @@ Status CumSum::Compute(OpKernelContext* ctx) const { if (output_shape.Size() == 0) return Status::OK(); - int64_t axis; + int64_t axis = 0; ORT_THROW_IF_ERROR(cumsum_op::GetAxis(axis_tensor, rank, axis)); auto dim(output_tensor.Shape()[axis]); // dimension size for the axis diff --git a/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc b/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc index f89e368e3b..b37872b8ae 100644 --- a/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc +++ b/onnxruntime/core/providers/cpu/reduction/reduction_ops.cc @@ -286,6 +286,10 @@ bool PrepareForReduce(const Tensor* input_tensor_ptr, return true; } + if (0 == first_dim) { + return false; + } + block_size = num_elements / first_dim; blocks = first_dim; diff --git a/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc b/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc index 58a7caeaa4..39be162f0b 100644 --- a/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc +++ b/onnxruntime/core/providers/cpu/tensor/unsqueeze.cc @@ -58,6 +58,7 @@ Status UnsqueezeBase::PrepareCompute(OpKernelContext* ctx, Prepare& p) const { TensorShape output_shape(output_dims); p.output_tensor = ctx->Output(0, output_shape); + ORT_ENFORCE(nullptr != p.output_tensor); p.input_tensor = &input_tensor; return Status::OK(); } @@ -65,9 +66,7 @@ Status UnsqueezeBase::PrepareCompute(OpKernelContext* ctx, Prepare& p) const { Status Unsqueeze::Compute(OpKernelContext* ctx) const { Prepare p; ORT_RETURN_IF_ERROR(PrepareCompute(ctx, p)); - CopyCpuTensor(p.input_tensor, p.output_tensor); - return Status::OK(); } } // namespace onnxruntime diff --git a/onnxruntime/test/onnx/tensorprotoutils.cc b/onnxruntime/test/onnx/tensorprotoutils.cc index c0a1fdd612..6b3df28b94 100644 --- a/onnxruntime/test/onnx/tensorprotoutils.cc +++ b/onnxruntime/test/onnx/tensorprotoutils.cc @@ -401,7 +401,7 @@ Status TensorProtoToMLValue(const onnx::TensorProto& tensor_proto, const MemBuff if (static_cast(tensor_size) > SIZE_MAX) { return Status(common::ONNXRUNTIME, common::INVALID_ARGUMENT, "Size overflow"); } - size_t size_to_allocate; + size_t size_to_allocate = 0; ORT_RETURN_IF_ERROR(GetSizeInBytesFromTensorProto<0>(tensor_proto, &size_to_allocate)); if (preallocated && preallocated_size < size_to_allocate)