diff --git a/src/opm/io/eclipse/rst/state.cpp b/src/opm/io/eclipse/rst/state.cpp index 1b0bf4bdc..887bb2dbb 100644 --- a/src/opm/io/eclipse/rst/state.cpp +++ b/src/opm/io/eclipse/rst/state.cpp @@ -380,13 +380,17 @@ void RstState::add_wlist(const std::vector& zwls, const auto& well_name = this->wells[well_index].name; for (auto wlist_index = 0*this->header.max_wlist; wlist_index < this->header.max_wlist; wlist_index++) { - int well_order = iwls[iwls_offset + wlist_index]; - if (well_order != 0) { - const auto& wlist_name = zwls[zwls_offset + wlist_index]; - auto& wlist = this->wlists[wlist_name]; - wlist.resize( well_order ); - wlist[well_order - 1] = well_name; + const auto well_order = iwls[iwls_offset + wlist_index]; + if (well_order < 1) { + continue; } + + auto& wlist = this->wlists[zwls[zwls_offset + wlist_index]]; + if (wlist.size() < static_cast::size_type>(well_order)) { + wlist.resize(well_order); + } + + wlist[well_order - 1] = well_name; } } }