code check

This commit is contained in:
jianghui58 2022-11-21 20:09:00 +08:00
parent fbfbbc6630
commit f4ea446e0d
1 changed files with 15 additions and 2 deletions

View File

@ -122,7 +122,13 @@ char *ReadFileSegment(const std::string &file, int64_t offset, int64_t len) {
}
ifs.seekg(0, std::ios::end);
size_t total_size = ifs.tellg();
auto goffset = ifs.tellg();
if (goffset < 0) {
MS_LOG(ERROR) << "read file range failed";
ifs.close();
return nullptr;
}
size_t total_size = static_cast<size_t>(goffset);
if (offset_pos + len_pos > total_size) {
MS_LOG(ERROR) << "file segment out of range";
ifs.close();
@ -171,7 +177,14 @@ char *ReadFile(const char *file, size_t *size) {
}
ifs->seekg(0, std::ios::end);
*size = ifs->tellg();
auto goffset = ifs->tellg();
if (goffset < 0) {
MS_LOG(ERROR) << "read file range failed";
ifs->close();
delete ifs;
return nullptr;
}
*size = static_cast<size_t>(goffset);
auto buf = new (std::nothrow) char[*size];
if (buf == nullptr) {
MS_LOG(ERROR) << "malloc buf failed, file: " << file;