From 7661ba74eda5b896f94286eb882efb216708ba4f Mon Sep 17 00:00:00 2001 From: Aki Koskinen Date: Tue, 6 Jan 2015 09:06:42 +0200 Subject: [PATCH] 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 Reviewed-by: Nikolai Kosjar --- src/libs/3rdparty/cplusplus/TranslationUnit.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp index 86eb25f1e35..4f1ff721390 100644 --- a/src/libs/3rdparty/cplusplus/TranslationUnit.cpp +++ b/src/libs/3rdparty/cplusplus/TranslationUnit.cpp @@ -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 newPosition(it->second.first, it->second.second + 1); _expandedLineColumn.insert(std::make_pair(newGreater.bytesBegin(), newPosition));