diff --git a/mindspore/lite/src/common/utils.cc b/mindspore/lite/src/common/utils.cc index 75ef38caffe..6dc7dd43fa7 100644 --- a/mindspore/lite/src/common/utils.cc +++ b/mindspore/lite/src/common/utils.cc @@ -54,6 +54,10 @@ uint64_t GetTimeUs() { std::string RemoveSubStr(const std::string &from, const std::string &sub_str, RemoveSubStrMode mode) { std::string result = from; + if (from.empty()) { + MS_LOG(ERROR) << "string is empty"; + return ""; + } if (mode == PREFIX) { if (from.substr(0, sub_str.length()) == sub_str) { result = from.substr(sub_str.size()); @@ -73,6 +77,10 @@ std::string RemoveSubStr(const std::string &from, const std::string &sub_str, Re } std::vector StrSplit(const std::string &str, const std::string &pattern) { + if (str.empty()) { + MS_LOG(ERROR) << "string is empty"; + return {}; + } std::string::size_type pos; std::vector result; std::string tmpStr(str + pattern); @@ -95,6 +103,11 @@ std::vector Tokenize(const std::string &src, const std::string &del return {}; } + if (src.empty()) { + MS_LOG(ERROR) << "string is empty"; + return {}; + } + std::vector tokens; size_t offset = 0; diff --git a/mindspore/lite/src/common/utils.h b/mindspore/lite/src/common/utils.h index 7b43164bb23..db023d6b3ed 100644 --- a/mindspore/lite/src/common/utils.h +++ b/mindspore/lite/src/common/utils.h @@ -106,6 +106,11 @@ inline Option ToString(bool value) { // get the file name from a given path // for example: "/usr/bin", we will get "bin" inline std::string GetFileName(const std::string &path) { + if (path.empty()) { + MS_LOG(ERROR) << "string is empty"; + return ""; + } + char delim = '/'; size_t i = path.rfind(delim, path.length()); diff --git a/mindspore/lite/src/executor.cc b/mindspore/lite/src/executor.cc index da51192cf0b..b8a816e5a93 100644 --- a/mindspore/lite/src/executor.cc +++ b/mindspore/lite/src/executor.cc @@ -19,7 +19,7 @@ #include "include/errorcode.h" namespace mindspore::lite { -int Executor::CheckInputs(std::vector &in_tensors) { +int Executor::CheckInputs(const std::vector &in_tensors) { for (auto &inTensor : in_tensors) { if (inTensor == nullptr) { MS_LOG(ERROR) << "Graph input tensor is nullptr"; diff --git a/mindspore/lite/src/executor.h b/mindspore/lite/src/executor.h index d9bfd6ae9bf..220361c9b89 100644 --- a/mindspore/lite/src/executor.h +++ b/mindspore/lite/src/executor.h @@ -35,7 +35,7 @@ class Executor { const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); protected: - static int CheckInputs(std::vector &in_tensors); + static int CheckInputs(const std::vector &in_tensors); }; } // namespace mindspore::lite #endif diff --git a/mindspore/lite/src/runtime/allocator.cc b/mindspore/lite/src/runtime/allocator.cc index 867e4083708..35ac8a7854d 100644 --- a/mindspore/lite/src/runtime/allocator.cc +++ b/mindspore/lite/src/runtime/allocator.cc @@ -88,6 +88,7 @@ void DefaultAllocator::Free(void *buf) { } UnLock(); free(buf); + buf = nullptr; } size_t DefaultAllocator::GetTotalSize() { diff --git a/mindspore/lite/tools/anf_importer/import_from_protobuf.cc b/mindspore/lite/tools/anf_importer/import_from_protobuf.cc index 23783252e1c..24797122b82 100644 --- a/mindspore/lite/tools/anf_importer/import_from_protobuf.cc +++ b/mindspore/lite/tools/anf_importer/import_from_protobuf.cc @@ -416,6 +416,10 @@ bool AnfImporterFromProtobuf::GetAttrValueForCNode(const PrimitivePtr &prim, con return false; } const std::string &ref_attr_name = attr_proto.ref_attr_name(); + if (ref_attr_name.empty()) { + MS_LOG(ERROR) << "ref_attr_name is empty"; + return false; + } string type = ""; std::size_t pos(0); if ((pos = ref_attr_name.find("scalar:")) != std::string::npos) { @@ -520,6 +524,10 @@ bool AnfImporterFromProtobuf::GetAttrValueForValueNode(const std::string &value_ return false; } const std::string &ref_attr_name = attr_proto.ref_attr_name(); + if (ref_attr_name.empty()) { + MS_LOG(ERROR) << "ref_attr_name is empty"; + return false; + } string type = ""; std::size_t pos(0); if ((pos = ref_attr_name.find("scalar:")) != std::string::npos) {