summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2023-11-10 15:29:53 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-11-14 06:43:41 +0000
commit37750aa8d158d44689e768ae3926dc842730dfcd (patch)
tree63c9ef42bd308dec76012b0cf33accb6c28d4282
parent66888203f6a2c8b73bc35644d45ac3c7a6c5809a (diff)
Don't reuse iterator var to avoid -D_GLIBCXX_DEBUG crash
For a CXXFLAGS='-D_GLIBCXX_DEBUG' build, running the examples/corelib/ipc/sharedmemory/sharedmemory example and clicking on the "Load Image from File..." button would result in a crash: > usr/include/c++/13/debug/safe_iterator.h:492: > In function: > bool gnu_debug::operator!=(const > _Safe_iterator<std::_Rb_tree_const_iterator<std::pair<const > QSettingsKey, QVariant> >, std::debug::map<QSettingsKey, QVariant, > std::less<QSettingsKey>, std::allocator<std::pair<const QSettingsKey, > QVariant> > >, std::forward_iterator_tag>::_Self&, const > _Safe_iterator<std::_Rb_tree_const_iterator<std::pair<const > QSettingsKey, QVariant> >, std::debug::map<QSettingsKey, QVariant, > std::less<QSettingsKey>, std::allocator<std::pair<const QSettingsKey, > QVariant> > >, std::forward_iterator_tag>::_Self&) > > Error: attempt to compare a singular iterator to a > singular (value-initialized) iterator. > > Objects involved in the operation: > iterator "lhs" @ 0x7ffe8e811550 { > type = std::_Rb_tree_const_iterator<std::pair<QSettingsKey const, QVariant> > (constant iterator); > state = singular; > } > iterator "rhs" @ 0x7ffe8e811670 { > type = std::_Rb_tree_const_iterator<std::pair<QSettingsKey const, QVariant> > (constant iterator); > state = singular (value-initialized); > } > Aborted (core dumped) This may be a libstdc++ bug, but still avoid/work around the issue by just using two separate variables for the iterators here. While at it, simplify the code a bit and replace the use of const_cast and pointers with the use of const references. Many thanks to Giuseppe D'Angelo for the analysis of the underlying problem and reporting a bug for GCC/libstdc++ [1] ! [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112477 Fixes: QTBUG-119044 Pick-to: 6.5 Change-Id: I00a8cc35033cf3ab4ba1f071cccabdef8ef52f9c Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> (cherry picked from commit 5db48d584e626a15bf436a56aa2165dfe9dfde1d) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/corelib/io/qsettings.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp
index 6bd9a2c819..d8d1419a51 100644
--- a/src/corelib/io/qsettings.cpp
+++ b/src/corelib/io/qsettings.cpp
@@ -1244,17 +1244,17 @@ QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec
else
ensureSectionParsed(confFile, thePrefix);
- auto j = const_cast<const ParsedSettingsMap *>(
- &confFile->originalKeys)->lowerBound( thePrefix);
- while (j != confFile->originalKeys.constEnd() && j.key().startsWith(thePrefix)) {
- if (!confFile->removedKeys.contains(j.key()))
- processChild(QStringView{j.key().originalCaseKey()}.sliced(startPos), spec, result);
- ++j;
+ const auto &originalKeys = confFile->originalKeys;
+ auto i = originalKeys.lowerBound(thePrefix);
+ while (i != originalKeys.end() && i.key().startsWith(thePrefix)) {
+ if (!confFile->removedKeys.contains(i.key()))
+ processChild(QStringView{i.key().originalCaseKey()}.sliced(startPos), spec, result);
+ ++i;
}
- j = const_cast<const ParsedSettingsMap *>(
- &confFile->addedKeys)->lowerBound(thePrefix);
- while (j != confFile->addedKeys.constEnd() && j.key().startsWith(thePrefix)) {
+ const auto &addedKeys = confFile->addedKeys;
+ auto j = addedKeys.lowerBound(thePrefix);
+ while (j != addedKeys.end() && j.key().startsWith(thePrefix)) {
processChild(QStringView{j.key().originalCaseKey()}.sliced(startPos), spec, result);
++j;
}