Skip to content

Commit b32f690

Browse files
committed
tom bugfix invalid iterator after insertion
1 parent a851cb5 commit b32f690

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

tom/src/tom/commands/command.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,13 @@ QStringList Command::optionNames() const
174174
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
175175
optionNames.insert(nthOption, commasCount, optionName);
176176
#else
177+
/* We need to save the index position because the nthOption iterator will be
178+
invalidated after an insertion. */
179+
const auto optionIdx = static_cast<int>(
180+
std::distance(optionNames.cbegin(), nthOption));
181+
177182
for (auto i = 0; i < commasCount ; ++i)
178-
optionNames.insert(static_cast<int>(std::distance(optionNames.cbegin(),
179-
nthOption)),
180-
optionName);
183+
optionNames.insert(optionIdx, optionName);
181184
#endif
182185
// Take into account also a newly inserted option names
183186
++nthOptionIdx += static_cast<decltype (nthOptionIdx)>(commasCount);

0 commit comments

Comments
 (0)