[Lldb-commits] [lldb] 98186de - [LLDB][Reliability] Fix accessing invalid iterator
Slava Gurevich via lldb-commits
lldb-commits at lists.llvm.org
Thu Jul 21 17:39:23 PDT 2022
Author: Slava Gurevich
Date: 2022-07-21T17:39:11-07:00
New Revision: 98186def3f1f6f3862e6c91ca01dfd278ad1929e
URL: https://github.com/llvm/llvm-project/commit/98186def3f1f6f3862e6c91ca01dfd278ad1929e
DIFF: https://github.com/llvm/llvm-project/commit/98186def3f1f6f3862e6c91ca01dfd278ad1929e.diff
LOG: [LLDB][Reliability] Fix accessing invalid iterator
Using invalidated vector iterator is at best a UB and could crash depending on STL implementation.
Fixing via minimal changes to preserve the existing code style.
Coverity warning 1454828 (scan.coverity.com)
Differential Revision: https://reviews.llvm.org/D130312
Added:
Modified:
lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
Removed:
################################################################################
diff --git a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
index 9a41a11ef5040..832057eb33087 100644
--- a/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
+++ b/lldb/source/Plugins/DynamicLoader/MacOSX-DYLD/DynamicLoaderMacOSXDYLD.cpp
@@ -610,8 +610,10 @@ bool DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress(
// Also copy over the uuid from the old entry to the removed entry so we
// can use it to lookup the module in the module list.
- ImageInfo::collection::iterator pos, end = m_dyld_image_infos.end();
- for (pos = m_dyld_image_infos.begin(); pos != end; pos++) {
+ bool found = false;
+
+ for (ImageInfo::collection::iterator pos = m_dyld_image_infos.begin();
+ pos != m_dyld_image_infos.end(); pos++) {
if (image_infos[idx].address == (*pos).address) {
image_infos[idx].uuid = (*pos).uuid;
@@ -635,11 +637,12 @@ bool DynamicLoaderMacOSXDYLD::RemoveModulesUsingImageInfosAddress(
// Then remove it from the m_dyld_image_infos:
m_dyld_image_infos.erase(pos);
+ found = true;
break;
}
}
- if (pos == end) {
+ if (!found) {
if (log) {
LLDB_LOGF(log, "Could not find image_info entry for unloading image:");
image_infos[idx].PutToLog(log);
More information about the lldb-commits
mailing list