Fix accessing of first character of an empty string.
GitOrigin-RevId: 9a4f25e6f46bacb397b43c88665a71da929a5531
This commit is contained in:
parent
4fb3506792
commit
d30d227289
@ -31,11 +31,13 @@ std::string get_file_contents(const std::string &file_name, const std::string &m
|
|||||||
std::size_t size = static_cast<std::size_t>(size_long);
|
std::size_t size = static_cast<std::size_t>(size_long);
|
||||||
|
|
||||||
std::string result(size, ' ');
|
std::string result(size, ' ');
|
||||||
std::rewind(f);
|
if (size != 0) {
|
||||||
std::size_t fread_res = std::fread(&result[0], size, 1, f);
|
std::rewind(f);
|
||||||
if (size != 0 && fread_res != 1) {
|
std::size_t fread_res = std::fread(&result[0], size, 1, f);
|
||||||
std::fprintf(stderr, "Can't read file \"%s\"", file_name.c_str());
|
if (fread_res != 1) {
|
||||||
std::abort();
|
std::fprintf(stderr, "Can't read file \"%s\"", file_name.c_str());
|
||||||
|
std::abort();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::fclose(f);
|
std::fclose(f);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user