From ab0ceacbed8c42a47bf6cf26dfd083a74d09f20b Mon Sep 17 00:00:00 2001 From: Michael Grupp Date: Tue, 2 Apr 2019 16:01:51 +0200 Subject: [PATCH] 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" --- cartographer/common/configuration_file_resolver.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/cartographer/common/configuration_file_resolver.cc b/cartographer/common/configuration_file_resolver.cc index 9774caf..3c2fd10 100644 --- a/cartographer/common/configuration_file_resolver.cc +++ b/cartographer/common/configuration_file_resolver.cc @@ -47,6 +47,7 @@ std::string ConfigurationFileResolver::GetFullPathOrDie( std::string ConfigurationFileResolver::GetFileContentOrDie( const std::string& basename) { + CHECK(!basename.empty()) << "File basename cannot be empty." << basename; const std::string filename = GetFullPathOrDie(basename); std::ifstream stream(filename.c_str()); return std::string((std::istreambuf_iterator(stream)),