Commit 7661ba74 authored by Aki Koskinen's avatar Aki Koskinen Committed by Nikolai Kosjar

Prevent using an invalidated reference

Inserting to a std::vector (possibly) invalidates all iterators and
references for it.

In this piece of code tok is a reference to a member in _tokens and it
should not be used after an insertion is made to _tokens. Switched the
order of two code lines to prevent this.

Change-Id: Ia9d1ce66fc67406f56b426e7431402c6fe68a38f
Reviewed-by: default avatarEike Ziller <>
Reviewed-by: default avatarNikolai Kosjar <>
parent e6f94433
......@@ -534,9 +534,10 @@ bool TranslationUnit::maybeSplitGreaterGreaterToken(unsigned tokenIndex)
newGreater.byteOffset = tok.byteOffset + 1;
newGreater.utf16charOffset = tok.utf16charOffset + 1;
TokenLineColumn::const_iterator it = _expandedLineColumn.find(tok.bytesBegin());
_tokens->insert(_tokens->begin() + tokenIndex + 1, newGreater);
TokenLineColumn::const_iterator it = _expandedLineColumn.find(tok.bytesBegin());
if (it != _expandedLineColumn.end()) {
const std::pair<unsigned, unsigned> newPosition(it->second.first, it->second.second + 1);
_expandedLineColumn.insert(std::make_pair(newGreater.bytesBegin(), newPosition));
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment