modify static check

pull/8923/head
yvette 4 years ago
parent 282f556f4a
commit 762b8b3046

@ -86,7 +86,11 @@ STATUS ConvertNcTensor2Nh(TensorT *tensor, const std::vector<int> &pad_dims) {
delete[] new_nhwc_data; delete[] new_nhwc_data;
return RET_ERROR; return RET_ERROR;
} }
memset(new_nhwc_data, 0, sizeof(float) * size); if (memset_s(new_nhwc_data, sizeof(float) * size, 0, sizeof(float) * size) != EOK) {
MS_LOG(ERROR) << "create new nhwc data failed";
delete[] new_nhwc_data;
return RET_ERROR;
}
auto nchw_data = reinterpret_cast<float *>(tensor->data.data()); auto nchw_data = reinterpret_cast<float *>(tensor->data.data());
// nchw to nhwc // nchw to nhwc
for (auto i = 0; i < batch; i++) { for (auto i = 0; i < batch; i++) {
@ -100,7 +104,11 @@ STATUS ConvertNcTensor2Nh(TensorT *tensor, const std::vector<int> &pad_dims) {
} }
} }
} }
memcpy(nchw_data, new_nhwc_data, sizeof(float) * size); if (memcpy_s(nchw_data, tensor->data.size(), new_nhwc_data, sizeof(float) * size) != EOK) {
MS_LOG(ERROR) << "memcpy_s failed";
delete[] new_nhwc_data;
return RET_ERROR;
}
delete[] new_nhwc_data; delete[] new_nhwc_data;
return RET_OK; return RET_OK;
} }
@ -129,7 +137,7 @@ STATUS GlobalFormatTransformPass::TransWeightToNhwc(MetaGraphT *graph, const std
MS_LOG(ERROR) << "tensor origin tensor size error"; MS_LOG(ERROR) << "tensor origin tensor size error";
return RET_ERROR; return RET_ERROR;
} }
if (origin_dims.size() == 0) { if (origin_dims.empty()) {
continue; continue;
} }
auto pad_dims = origin_dims; auto pad_dims = origin_dims;

@ -35,7 +35,7 @@ int Cropper::ReadPackage() {
MS_LOG(DEBUG) << cmd; MS_LOG(DEBUG) << cmd;
FILE *p_file = popen(cmd.c_str(), "r"); FILE *p_file = popen(cmd.c_str(), "r");
if (!p_file) { if (p_file == nullptr) {
MS_LOG(ERROR) << "Error to popen" << this->flags_->package_file_; MS_LOG(ERROR) << "Error to popen" << this->flags_->package_file_;
return RET_ERROR; return RET_ERROR;
} }
@ -140,13 +140,14 @@ int Cropper::GetModelFiles() {
char buf[BUF_SIZE]; char buf[BUF_SIZE];
FILE *p_file = popen(cmd.c_str(), "r"); FILE *p_file = popen(cmd.c_str(), "r");
if (!p_file) { if (p_file == nullptr) {
MS_LOG(ERROR) << "Error to popen"; MS_LOG(ERROR) << "Error to popen";
return RET_ERROR; return RET_ERROR;
} }
while (fgets(buf, BUF_SIZE, p_file) != nullptr) { while (fgets(buf, BUF_SIZE, p_file) != nullptr) {
String realPath = RealPath(String(buf).substr(0, String(buf).length() - 1).c_str()); String realPath = RealPath(String(buf).substr(0, String(buf).length() - 1).c_str());
if (realPath.empty()) { if (realPath.empty()) {
pclose(p_file);
return RET_INPUT_PARAM_INVALID; return RET_INPUT_PARAM_INVALID;
} }
this->model_files_.emplace_back(realPath); this->model_files_.emplace_back(realPath);

@ -69,7 +69,11 @@ STATUS GenNewConvBias(const ParameterPtr &down_bias_node, const ParameterPtr &do
MS_LOG(ERROR) << "tensor_data is nullptr"; MS_LOG(ERROR) << "tensor_data is nullptr";
return RET_ERROR; return RET_ERROR;
} }
memset(new_bias_data, 0, new_bias_size * sizeof(float)); if (memset_s(new_bias_data, new_bias_size * sizeof(float), 0, new_bias_size * sizeof(float)) != EOK) {
MS_LOG(ERROR) << "memset_s failed";
delete[] new_bias_data;
return RET_ERROR;
}
auto up_bias_size = up_bias_shape[0]; auto up_bias_size = up_bias_shape[0];
for (int i = 0; i < new_bias_size; i++) { for (int i = 0; i < new_bias_size; i++) {
for (int j = 0; j < up_bias_size; j++) { for (int j = 0; j < up_bias_size; j++) {
@ -112,8 +116,11 @@ STATUS GenNewConvWeight(const ParameterPtr &down_weight_node, const ParameterPtr
MS_LOG(ERROR) << "tensor_data is nullptr"; MS_LOG(ERROR) << "tensor_data is nullptr";
return RET_ERROR; return RET_ERROR;
} }
memset(new_weight_data, 0, size * sizeof(float)); if (memset_s(new_weight_data, size * sizeof(float), 0, size * sizeof(float)) != EOK) {
MS_LOG(ERROR) << "memset_s failed";
delete[] new_weight_data;
return RET_ERROR;
}
for (int i = 0; i < cout1; i++) { for (int i = 0; i < cout1; i++) {
auto down_weight_base = i * cout0; auto down_weight_base = i * cout0;
auto new_weight_base = i * window_size * cin0; auto new_weight_base = i * window_size * cin0;

@ -89,8 +89,9 @@ STATUS InferShapePass::SetParameterAbstract(const ParameterPtr &parameter) {
return RET_ERROR; return RET_ERROR;
} }
auto ret = memcpy_s(tensor_data, new_value->tensor_size(), param_value->tensor_addr(), param_value->tensor_size()); auto ret = memcpy_s(tensor_data, new_value->tensor_size(), param_value->tensor_addr(), param_value->tensor_size());
if (ret != RET_OK) { if (ret != EOK) {
MS_LOG(ERROR) << "memcpy error: " << ret; MS_LOG(ERROR) << "memcpy error: " << ret;
delete[] tensor_data;
return RET_ERROR; return RET_ERROR;
} }
new_value->set_tensor_addr(tensor_data); new_value->set_tensor_addr(tensor_data);

Loading…
Cancel
Save