Check for empty basename in GetFileContentOrDie() (#1558)
An empty basename would mean a directory path is returned by GetFullPathOrDie(), which then leads to a cryptic exception when trying to read from it using the istreambuf_iterator: "basic_filebuf::underflow error reading the file: iostream error"master
parent
98197cff4f
commit
ab0ceacbed
|
@ -47,6 +47,7 @@ std::string ConfigurationFileResolver::GetFullPathOrDie(
|
||||||
|
|
||||||
std::string ConfigurationFileResolver::GetFileContentOrDie(
|
std::string ConfigurationFileResolver::GetFileContentOrDie(
|
||||||
const std::string& basename) {
|
const std::string& basename) {
|
||||||
|
CHECK(!basename.empty()) << "File basename cannot be empty." << basename;
|
||||||
const std::string filename = GetFullPathOrDie(basename);
|
const std::string filename = GetFullPathOrDie(basename);
|
||||||
std::ifstream stream(filename.c_str());
|
std::ifstream stream(filename.c_str());
|
||||||
return std::string((std::istreambuf_iterator<char>(stream)),
|
return std::string((std::istreambuf_iterator<char>(stream)),
|
||||||
|
|
Loading…
Reference in New Issue