-
Notifications
You must be signed in to change notification settings - Fork 4k
Open
Description
Description
The BFS algorithm crashes with an "Exception 0x80000003" (access violation) and an assertion failure "cannot dereference end list iterator" during graph traversal. The crash occurs specifically when processing queue elements and accessing the graph structure.
Reproduction Steps
- Build and execute the provided BFS implementation
- Initialize graph with the test data:
graph.insert({"you", {"alice", "bob", "claire"}}); ... // Other nodes - Start search from node "you"
- Program crashes during queue processing
Error Log
Exception 0x80000003 encountered at address 0x7ff6f69aba73
File: MSVC include\list Line: 147
Expression: cannot dereference end list iterator
Root Cause Analysis
-
Dangling Reference
- Original code used
T& person = search_queue.front()followed bypop() - Created invalid reference to queue data after element removal
- Subsequent access to
personcaused undefined behavior
- Original code used
-
Unsafe Iterator Dereference
- Direct dereference of
graph.find()->secondwithout existence check - Risk of accessing
end()iterator when key not found
- Direct dereference of
-
Incomplete Graph Validation
- No validation for node existence when processing friends lists
- Potential null-dereference for missing graph nodes
Proposed Fix
// 1. Safe queue element access
T person = search_queue.front(); // Copy instead of reference
search_queue.pop();
// 2. Validate graph nodes before access
auto start_it = graph.find(name);
if (start_it == graph.end()) {
return false; // Handle missing start node
}
// 3. Secure friend list processing
auto person_it = graph.find(person);
if (person_it != graph.end()) {
for (const auto& friend_name : person_it->second) {
search_queue.push(friend_name);
}
}Verification
After applying these changes:
- Test case successfully finds "thom" as mango seller
- Stress tests with missing nodes no longer crash
- Valgrind/memory checks show clean reports
Severity: Critical (Crash/Data Corruption)
Priority: P1 (Must Fix)
Affected Versions: All versions prior to 2023-04-07
Suggested Additional Improvements
- Add unit tests for:
- Missing start node
- Nodes with empty friend lists
- Multiple consecutive sellers
- Implement graph validation wrapper
- Add error logging for missing nodes
Environment
- OS: Windows 10/11
- Compiler: MSVC 2022 (v14.34-17.8)
- Build Config: Debug x64
- STL Version: MSVC STL 2022
Attachments
Metadata
Metadata
Assignees
Labels
No labels