Skip to content

Commit

Permalink
fix: add empty check and iterator validation in ContainerIterator::ad…
Browse files Browse the repository at this point in the history
…vance()

Description:
This PR adds an !over.empty() check in ContainerIterator::advance() to ensure the iterator does not access an empty queue or go out of bounds during container iteration.

Key Changes:

Added validation to prevent accessing over.front() when the over queue is empty.
Ensured the iterator cur is correctly repositioned to the next container, preventing out-of-bounds access to itemlist.
This improves the stability and prevents potential crashes during container iteration.
  • Loading branch information
dudantas committed Sep 16, 2024
1 parent 687aba5 commit 61b5701
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/items/containers/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ void ContainerIterator::advance() {

++cur;

if (cur == over.front()->itemlist.end()) {
if (!over.empty() && cur == over.front()->itemlist.end()) {
over.pop_front();
if (!over.empty()) {
cur = over.front()->itemlist.begin();
Expand Down

0 comments on commit 61b5701

Please sign in to comment.