diff --git a/include/api/cell.h b/include/api/cell.h index e0813467666..fa41d061921 100644 --- a/include/api/cell.h +++ b/include/api/cell.h @@ -84,7 +84,7 @@ class MS_API InputAndOutput { private: std::shared_ptr cell_; std::vector prev_; - int32_t index_; + int32_t index_ = 0; }; } // namespace mindspore #endif // MINDSPORE_INCLUDE_API_CELL_H diff --git a/include/api/types.h b/include/api/types.h index fa5e1d53732..9a1d6dd6291 100644 --- a/include/api/types.h +++ b/include/api/types.h @@ -352,8 +352,8 @@ void MSTensor::SetTensorName(const std::string &name) { return SetTensorName(Str using Key = struct Key { const size_t max_key_len = 32; - size_t len; - unsigned char key[32]; + size_t len = 0; + unsigned char key[32] = {0}; Key() : len(0) {} explicit Key(const char *dec_key, size_t key_len); }; diff --git a/mindspore/lite/src/common/decrypt.cc b/mindspore/lite/src/common/decrypt.cc index d7be33c8894..23a56960965 100644 --- a/mindspore/lite/src/common/decrypt.cc +++ b/mindspore/lite/src/common/decrypt.cc @@ -74,7 +74,7 @@ bool ParseEncryptData(const Byte *encrypt_data, size_t encrypt_len, std::vector< } int_buf.assign(encrypt_data, encrypt_data + sizeof(int32_t)); auto iv_len = ByteToInt(int_buf.data(), int_buf.size()); - if (iv_len <= 0 || iv_len + sizeof(int32_t) + sizeof(int32_t) > encrypt_len) { + if (iv_len <= 0 || static_cast(iv_len) + sizeof(int32_t) + sizeof(int32_t) > encrypt_len) { MS_LOG(ERROR) << "assign len is invalid."; return false; } @@ -87,7 +87,8 @@ bool ParseEncryptData(const Byte *encrypt_data, size_t encrypt_len, std::vector< } (*iv).assign(encrypt_data + sizeof(int32_t), encrypt_data + sizeof(int32_t) + iv_len); - if (cipher_len <= 0 || sizeof(int32_t) + iv_len + sizeof(int32_t) + cipher_len > encrypt_len) { + if (cipher_len <= 0 || + sizeof(int32_t) + static_cast(iv_len) + sizeof(int32_t) + static_cast(cipher_len) > encrypt_len) { MS_LOG(ERROR) << "assign len is invalid."; return false; } @@ -300,7 +301,7 @@ std::unique_ptr Decrypt(const std::string &lib_path, size_t *decrypt_len MS_LOG(ERROR) << "The block_size read from the cipher data must be not negative, but got " << block_size; return nullptr; } - if (offset + block_size > data_size) { + if (offset + static_cast(block_size) > data_size) { MS_LOG(ERROR) << "assign len is invalid."; return nullptr; } diff --git a/mindspore/lite/src/common/quant_utils.cc b/mindspore/lite/src/common/quant_utils.cc index d0ef3ccbdcd..757c3c80c8f 100644 --- a/mindspore/lite/src/common/quant_utils.cc +++ b/mindspore/lite/src/common/quant_utils.cc @@ -103,7 +103,7 @@ int CalQuantizationParams(schema::QuantParamT *quant_param, double real_min, dou int GetBucketIndex(const std::vector &dims, int preferred_dim, int data_index) { int stride = 1; int bucket_count = dims[preferred_dim]; - for (size_t i = preferred_dim + 1; i < dims.size(); i++) { + for (size_t i = static_cast(preferred_dim + 1); i < dims.size(); i++) { stride *= dims[i]; } if (stride == 0 || bucket_count == 0) { @@ -134,8 +134,11 @@ int CalPerChannelGain(size_t bit_num, const std::vector &dims, int preferre const int bits_per_byte = 8; const int quant_param_size = 32; int channels = dims.at(preferred_dim); - CHECK_LESS_RETURN(channels, 1); - size_t bucket_size = elem_count / channels; + if (channels < 1) { + MS_LOG(ERROR) << "channels must not less 1"; + return RET_ERROR; + } + size_t bucket_size = static_cast(elem_count / channels); bool do_quant = (quant_param_size * bits_per_byte) / (sizeof(float) * bits_per_byte - bit_num) < bucket_size; if (do_quant) { return RET_OK; @@ -157,7 +160,7 @@ int CalWeightQuantBias(const float *raw_datas, size_t elem_count, const std::vec std::map var_raws; std::map var_dequants; size_t bucket_size = quant_params->size(); - int bucket_volume = elem_count / dims[preferred_dim]; + int bucket_volume = static_cast(elem_count / dims[preferred_dim]); // Init Map for (size_t i = 0; i < bucket_size; i++) { total_raws[i] = 0; diff --git a/mindspore/lite/src/common/string_util.cc b/mindspore/lite/src/common/string_util.cc index 4d0ce31c070..41687114ba7 100644 --- a/mindspore/lite/src/common/string_util.cc +++ b/mindspore/lite/src/common/string_util.cc @@ -59,7 +59,8 @@ int WriteStringsToTensor(Tensor *tensor, const std::vector &string_b } size_t num = string_buffer.size(); std::vector offset(num + 1); - offset[0] = 4 * (num + 2); + const size_t extra_offset_num = 2; + offset[0] = static_cast(sizeof(int32_t) * (num + extra_offset_num)); for (size_t i = 0; i < num; i++) { offset[i + 1] = offset[i] + string_buffer[i].len; } @@ -92,7 +93,8 @@ int WriteSeperatedStringsToTensor(Tensor *tensor, const std::vector offset(num + 1); - offset[0] = 4 * (num + 2); + const size_t extra_offset_num = 2; + offset[0] = static_cast(sizeof(int32_t) * (num + extra_offset_num)); std::vector len(num); for (size_t i = 0; i < num; i++) { len[i] = 0;