From 0d9db2b28d7ca72865405d7fbe47c6221f01d4ab Mon Sep 17 00:00:00 2001 From: Josh Bradley Date: Wed, 24 Jun 2020 21:56:14 -0400 Subject: [PATCH] add informative error message regarding symbolic dimensions (#4297) * add informative error message regarding symbolic dimensions * fix code format and move negative value check in for loop --- onnxruntime/core/session/onnxruntime_c_api.cc | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index f7db1d9c58..1f5bf29ae2 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -158,6 +158,8 @@ ORT_STATUS_PTR CreateTensorImpl(MLDataType ml_type, const int64_t* shape, size_t size_t elem_count = 1; std::vector shapes(shape_len); for (size_t i = 0; i != shape_len; ++i) { + if (shape[i] < 0) + return OrtApis::CreateStatus(ORT_INVALID_ARGUMENT, "tried creating tensor with negative value in shape"); elem_count *= static_cast(shape[i]); shapes[i] = shape[i]; } @@ -1376,16 +1378,16 @@ ORT_API_STATUS_IMPL(OrtApis::GetOpaqueValue, _In_ const char* domain_name, _In_ return nullptr; } -ORT_API_STATUS_IMPL(OrtApis::GetAvailableProviders, _Outptr_ char ***out_ptr, - _In_ int *providers_length) { +ORT_API_STATUS_IMPL(OrtApis::GetAvailableProviders, _Outptr_ char*** out_ptr, + _In_ int* providers_length) { API_IMPL_BEGIN const size_t MAX_LEN = 30; - int available_count = (int)(sizeof(providers_available) / sizeof(char *)); - char **out = (char **)malloc(available_count * sizeof(char *)); - if(out) { - for(int i = 0; i < available_count; i++) { - out[i] = (char *)malloc((MAX_LEN + 1) * sizeof(char)); - if(out[i]) { + int available_count = (int)(sizeof(providers_available) / sizeof(char*)); + char** out = (char**)malloc(available_count * sizeof(char*)); + if (out) { + for (int i = 0; i < available_count; i++) { + out[i] = (char*)malloc((MAX_LEN + 1) * sizeof(char)); + if (out[i]) { #ifdef _MSC_VER strncpy_s(out[i], MAX_LEN, providers_available[i], MAX_LEN); #else @@ -1401,12 +1403,12 @@ ORT_API_STATUS_IMPL(OrtApis::GetAvailableProviders, _Outptr_ char ***out_ptr, return NULL; } -ORT_API_STATUS_IMPL(OrtApis::ReleaseAvailableProviders, _In_ char **ptr, +ORT_API_STATUS_IMPL(OrtApis::ReleaseAvailableProviders, _In_ char** ptr, _In_ int providers_length) { API_IMPL_BEGIN - if(ptr) { - for(int i = 0; i < providers_length; i++) { - if(ptr[i]) { + if (ptr) { + for (int i = 0; i < providers_length; i++) { + if (ptr[i]) { free(ptr[i]); } }