Incorrect vector construction in pgsql selection of historic nodes/ways/relations
Closed this issue · 1 comments
When selecting historic nodes/ways/relations from the pgsql database, the id and version vectors are created via
std::vector<osm_nwr_id_t> ids(eds.size());
std::vector<osm_version_t> vers(eds.size());
for (const auto &ed : eds) {
ids.emplace_back(ed.first);
vers.emplace_back(ed.second);
}
Presumably the vector is intended to be constructed with an appropriated pre-allocated/reserved size, but unfortunately the used vector( size_type count );
constructor actually fills the vector with count
default inserted elements. That means the ids
/vers
vectors are created with eds.size()
elements with value 0
and then the real id/version elements are inserted in addition.
reserve(eds.size())
should be used instead (which is actually how it used to be previously)
https://en.cppreference.com/w/cpp/container/vector/vector (4)
Thanks, good catch, this should have been reserve instead, similar issues further down the in the same file. As we don’t have object / version 0 in the database, it won’t change the result.