From: @lyvette Reviewed-by: @hangangqiang,@zhanghaibo5 Signed-off-by: @hangangqiangtags/v1.1.0
| @@ -54,6 +54,10 @@ uint64_t GetTimeUs() { | |||||
| std::string RemoveSubStr(const std::string &from, const std::string &sub_str, RemoveSubStrMode mode) { | std::string RemoveSubStr(const std::string &from, const std::string &sub_str, RemoveSubStrMode mode) { | ||||
| std::string result = from; | std::string result = from; | ||||
| if (from.empty()) { | |||||
| MS_LOG(ERROR) << "string is empty"; | |||||
| return ""; | |||||
| } | |||||
| if (mode == PREFIX) { | if (mode == PREFIX) { | ||||
| if (from.substr(0, sub_str.length()) == sub_str) { | if (from.substr(0, sub_str.length()) == sub_str) { | ||||
| result = from.substr(sub_str.size()); | 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<std::string> StrSplit(const std::string &str, const std::string &pattern) { | std::vector<std::string> 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::string::size_type pos; | ||||
| std::vector<std::string> result; | std::vector<std::string> result; | ||||
| std::string tmpStr(str + pattern); | std::string tmpStr(str + pattern); | ||||
| @@ -95,6 +103,11 @@ std::vector<std::string> Tokenize(const std::string &src, const std::string &del | |||||
| return {}; | return {}; | ||||
| } | } | ||||
| if (src.empty()) { | |||||
| MS_LOG(ERROR) << "string is empty"; | |||||
| return {}; | |||||
| } | |||||
| std::vector<std::string> tokens; | std::vector<std::string> tokens; | ||||
| size_t offset = 0; | size_t offset = 0; | ||||
| @@ -106,6 +106,11 @@ inline Option<std::string> ToString(bool value) { | |||||
| // get the file name from a given path | // get the file name from a given path | ||||
| // for example: "/usr/bin", we will get "bin" | // for example: "/usr/bin", we will get "bin" | ||||
| inline std::string GetFileName(const std::string &path) { | inline std::string GetFileName(const std::string &path) { | ||||
| if (path.empty()) { | |||||
| MS_LOG(ERROR) << "string is empty"; | |||||
| return ""; | |||||
| } | |||||
| char delim = '/'; | char delim = '/'; | ||||
| size_t i = path.rfind(delim, path.length()); | size_t i = path.rfind(delim, path.length()); | ||||
| @@ -19,7 +19,7 @@ | |||||
| #include "include/errorcode.h" | #include "include/errorcode.h" | ||||
| namespace mindspore::lite { | namespace mindspore::lite { | ||||
| int Executor::CheckInputs(std::vector<Tensor *> &in_tensors) { | |||||
| int Executor::CheckInputs(const std::vector<Tensor *> &in_tensors) { | |||||
| for (auto &inTensor : in_tensors) { | for (auto &inTensor : in_tensors) { | ||||
| if (inTensor == nullptr) { | if (inTensor == nullptr) { | ||||
| MS_LOG(ERROR) << "Graph input tensor is nullptr"; | MS_LOG(ERROR) << "Graph input tensor is nullptr"; | ||||
| @@ -35,7 +35,7 @@ class Executor { | |||||
| const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); | const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr); | ||||
| protected: | protected: | ||||
| static int CheckInputs(std::vector<Tensor *> &in_tensors); | |||||
| static int CheckInputs(const std::vector<Tensor *> &in_tensors); | |||||
| }; | }; | ||||
| } // namespace mindspore::lite | } // namespace mindspore::lite | ||||
| #endif | #endif | ||||
| @@ -88,6 +88,7 @@ void DefaultAllocator::Free(void *buf) { | |||||
| } | } | ||||
| UnLock(); | UnLock(); | ||||
| free(buf); | free(buf); | ||||
| buf = nullptr; | |||||
| } | } | ||||
| size_t DefaultAllocator::GetTotalSize() { | size_t DefaultAllocator::GetTotalSize() { | ||||
| @@ -416,6 +416,10 @@ bool AnfImporterFromProtobuf::GetAttrValueForCNode(const PrimitivePtr &prim, con | |||||
| return false; | return false; | ||||
| } | } | ||||
| const std::string &ref_attr_name = attr_proto.ref_attr_name(); | 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 = ""; | string type = ""; | ||||
| std::size_t pos(0); | std::size_t pos(0); | ||||
| if ((pos = ref_attr_name.find("scalar:")) != std::string::npos) { | if ((pos = ref_attr_name.find("scalar:")) != std::string::npos) { | ||||
| @@ -520,6 +524,10 @@ bool AnfImporterFromProtobuf::GetAttrValueForValueNode(const std::string &value_ | |||||
| return false; | return false; | ||||
| } | } | ||||
| const std::string &ref_attr_name = attr_proto.ref_attr_name(); | 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 = ""; | string type = ""; | ||||
| std::size_t pos(0); | std::size_t pos(0); | ||||
| if ((pos = ref_attr_name.find("scalar:")) != std::string::npos) { | if ((pos = ref_attr_name.find("scalar:")) != std::string::npos) { | ||||