This looks like an existing bug, but if there were already elements in 'out', this might not reserve enough. You would want:

out.reserve(out.size() + std::min(...));

Up to you if you think worth fixing.