Suspicious iterator access in BinaryProvider
GCC 10 has an "array-bounds" warning that complains about the following code in BinaryProvider.h:
void order_files(std::vector<std::string>& files, EventIDs const& order, std::string const& folder)
{
std::map<std::tuple<int, long long>, std::string> file_ids;
for (auto file : files) {
file_ids.emplace(name_to_number(file), file);
}
files.clear();
for (auto event_id : order) {
auto file_it = file_ids.find(event_id);
if (file_it != file_ids.end()) {
files.emplace_back(std::move(file_it->second));
}
else {
auto [run, event] = file_it->first; // <= This is the line that makes GCC unhappy
throw StrException {std::string {"file with event ID "} + std::to_string(run) + " " + std::to_string(event) +
" not found in " + folder};
}
}
}
...and intuitively I would tend to agree with the warning. If you just checked that an iterator is invalid, proceeding to dereference it is suspicious to say the least!
I assume that the goal was to destructure the event_id
key that was used to access the map, but if that was the intent, why not destructure event_id
directly?