Skip to content

Possible invalid iterator#705

Open
lucassdiass wants to merge 1 commit into
savoirfairelinux:masterfrom
lucassdiass:invalid_iterator
Open

Possible invalid iterator#705
lucassdiass wants to merge 1 commit into
savoirfairelinux:masterfrom
lucassdiass:invalid_iterator

Conversation

@lucassdiass

Copy link
Copy Markdown
Contributor

nodes pop_back could execute more than one time.
In this case, the iterator will be invalid in the comparison with nodes.end, so iterator must be adjusted.

If the change is invalid or doesn't make sense, while loop could be replaced by an if condition

nodes pop_back could execute more than one time.
In this case, iterator will be invalid in the comparison
with nodes.end, so iterator must be adjusted.

Signed-off-by: Lucas Dias <lucas_dias@redes.ufsm.br>
@aberaud

aberaud commented May 30, 2024

Copy link
Copy Markdown
Member

Thanks for the PR for this delicate part of code. Please check my comment.

@lucassdiass

Copy link
Copy Markdown
Contributor Author

You're welcome. Sorry, I don't understand, what's the comment for me to check?

@lucassdiass

Copy link
Copy Markdown
Contributor Author

I have a question. Do you think changing the removeExpiredNode() call before line 847 makes sense? This call will remove expired nodes and free space for a new one.

Comment thread src/search.h
return false;
// For some reason if removindNode was false, iterator could be
// invalid.
n = nodes.end();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current logic, n must always be the inserted node. If snode is inserted at the beginning of the list and the list if trimmed, n would be set to an invalid node.

@aberaud

aberaud commented May 31, 2024

Copy link
Copy Markdown
Member

You're welcome. Sorry, I don't understand, what's the comment for me to check?

Yeah sorry i forgot to submit the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants