Doing an .insert() can potentially invalidate iterators by reallocating the vector's storage. When all the stars align just right, this causes segfaults or glibc aborts. Fix this by recomputing the position before each insert.
Gentoo Linux bug (crashes while building Chromium): https://bugs.gentoo.org/650082