Merge pull request #982 from akva2/fix_negative_index_deref

fixed: dereferencing string at index -1 is not adviced.
This commit is contained in:
Joakim Hove
2019-08-30 19:09:13 +02:00
committed by GitHub

View File

@@ -49,12 +49,11 @@ namespace {
bool isFormatted(const std::string& filename)
{
int p = filename.find_last_of(".");
int l = filename.length();
std::string extension = filename.substr(p,l-p);
return extension.substr(1,1) == "F" || extension.substr(1,1) == "A";
const auto p = filename.find_last_of(".");
if (p == std::string::npos)
OPM_THROW(std::invalid_argument,
"Purported ECLIPSE Filename'" + filename + "'does not contain extension");
return std::strchr("ABCFGH", static_cast<int>(filename[p+1])) != nullptr;
}