Fix accessing of first character of an empty string.

GitOrigin-RevId: 9a4f25e6f46bacb397b43c88665a71da929a5531
This commit is contained in:
levlam 2018-06-30 03:46:56 +03:00
parent 4fb3506792
commit d30d227289

View File

@ -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::string result(size, ' ');
std::rewind(f);
std::size_t fread_res = std::fread(&result[0], size, 1, f);
if (size != 0 && fread_res != 1) {
std::fprintf(stderr, "Can't read file \"%s\"", file_name.c_str());
std::abort();
if (size != 0) {
std::rewind(f);
std::size_t fread_res = std::fread(&result[0], size, 1, f);
if (fread_res != 1) {
std::fprintf(stderr, "Can't read file \"%s\"", file_name.c_str());
std::abort();
}
}
std::fclose(f);