From c91d4ed38fa97c1879db2b9bf5377aff6d6f4de7 Mon Sep 17 00:00:00 2001 From: TonyWang222 Date: Tue, 31 Jan 2023 14:53:57 +0800 Subject: [PATCH] change malloc to malloc_s Change-Id: I1ee2ad22ac436fddb30250ae1744ac97288aee1b Signed-off-by: TonyWang222 --- ai/mindspore/BUILD.gn | 1 + ai/mindspore/src/ohos_c_api_test_mslite.cpp | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ai/mindspore/BUILD.gn b/ai/mindspore/BUILD.gn index 4d30362a2..108c52833 100644 --- a/ai/mindspore/BUILD.gn +++ b/ai/mindspore/BUILD.gn @@ -28,6 +28,7 @@ ohos_moduletest_suite("ActsMindSporeTest") { configs = [ ":mindspore_config" ] + external_deps = [ "c_utils:utils" ] deps = [ "//third_party/googletest:gmock", "//third_party/googletest:gtest", diff --git a/ai/mindspore/src/ohos_c_api_test_mslite.cpp b/ai/mindspore/src/ohos_c_api_test_mslite.cpp index 49573fe34..d86cd2869 100644 --- a/ai/mindspore/src/ohos_c_api_test_mslite.cpp +++ b/ai/mindspore/src/ohos_c_api_test_mslite.cpp @@ -15,6 +15,7 @@ #include #include +#include #include "ohos_common.h" #include "gtest/gtest.h" #include "include/c_api/context_c.h" @@ -90,9 +91,9 @@ void FillInputsData(OH_AI_TensorHandleArray inputs, string model_name, bool is_t const int64_t *shape = OH_AI_TensorGetShape(tensor, &shape_num); auto imageBuf_nhwc = new char[size1]; PackNCHWToNHWCFp32(imageBuf, imageBuf_nhwc, shape[0], shape[1] * shape[2], shape[3]); - memcpy(input_data, imageBuf_nhwc, size1); + memcpy_s(input_data, size1, imageBuf_nhwc, size1); } else { - memcpy(input_data, imageBuf, size1); + memcpy_s(input_data, size1, imageBuf, size1); } printf("input data after filling is: "); for (int j = 0; j < element_num && j <= 20; ++j) { @@ -958,7 +959,7 @@ HWTEST(MSLiteTest, OHOS_Model_GetInputByTensorName_0001, Function | MediumTest | const int64_t *shape = OH_AI_TensorGetShape(tensor, &shape_num); auto imageBuf_nhwc = new char[size1]; PackNCHWToNHWCFp32(imageBuf, imageBuf_nhwc, shape[0], shape[1] * shape[2], shape[3]); - memcpy(input_data, imageBuf_nhwc, size1); + memcpy_s(input_data, size1, imageBuf_nhwc, size1); printf("input data is:"); for (int j = 0; j < element_num && j <= 20; ++j) { printf("%f ", input_data[j]); @@ -1479,7 +1480,7 @@ HWTEST(MSLiteTest, OHOS_Input_0003, Function | MediumTest | Level1) { printf("Tensor name: %s, elements num: %" PRId64 ".\n", OH_AI_TensorGetName(tensor), element_num); void *input_data = OH_AI_TensorGetMutableData(inputs.handle_list[i]); ASSERT_NE(input_data, nullptr); - memcpy(input_data, imageBuf, size1); + memcpy_s(input_data, size1, imageBuf, size1); } printf("==========Model Predict==========\n"); OH_AI_TensorHandleArray outputs; -- GitLab