A C++ iterator is a lot like a C pointer: if you dereference it without first checking that it's valid then it can cause a crash.

Always check that the iterator is valid before derefencing it.

Issue 1763 was caused by this dereference of the iterator pos. The bug was fixed by not dereferencing pos if pos == metadata->end().