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: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
This commit is contained in:
Aki Koskinen
2015-01-06 09:06:42 +02:00
committed by Nikolai Kosjar
parent e6f9443394
commit 7661ba74ed

View File

@@ -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));