modify static check

This commit is contained in:
yvette 2020-11-26 10:32:41 +08:00
parent 386f6e0d2b
commit 1cedf86d43
6 changed files with 29 additions and 2 deletions

View File

@ -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<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::vector<std::string> result;
std::string tmpStr(str + pattern);
@ -95,6 +103,11 @@ std::vector<std::string> Tokenize(const std::string &src, const std::string &del
return {};
}
if (src.empty()) {
MS_LOG(ERROR) << "string is empty";
return {};
}
std::vector<std::string> tokens;
size_t offset = 0;

View File

@ -106,6 +106,11 @@ inline Option<std::string> 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());

View File

@ -19,7 +19,7 @@
#include "include/errorcode.h"
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) {
if (inTensor == nullptr) {
MS_LOG(ERROR) << "Graph input tensor is nullptr";

View File

@ -35,7 +35,7 @@ class Executor {
const KernelCallBack &before = nullptr, const KernelCallBack &after = nullptr);
protected:
static int CheckInputs(std::vector<Tensor *> &in_tensors);
static int CheckInputs(const std::vector<Tensor *> &in_tensors);
};
} // namespace mindspore::lite
#endif

View File

@ -88,6 +88,7 @@ void DefaultAllocator::Free(void *buf) {
}
UnLock();
free(buf);
buf = nullptr;
}
size_t DefaultAllocator::GetTotalSize() {

View File

@ -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) {