Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MolDraw2D::drawMolecules() should not crash on null molecules #5503

Merged
merged 2 commits into from
Sep 6, 2022

Conversation

ptosco
Copy link
Contributor

@ptosco ptosco commented Aug 17, 2022

This bug was originally reported by Richard Lewis.
MolDraw2D::drawMolecules() under certain conditions will attempt to access non-existent vector items and hence segfault.
This simple PR fixes the problem and adds a test.

@@ -231,12 +232,13 @@ void MolDraw2D::drawMolecules(
drawMols_.back()->setOffsets(col * panelWidth(), row * panelHeight());
drawMols_.back()->createDrawObjects();
if (drawMols_.back()->getScale() < drawMols_[minScaleMol]->getScale()) {
minScaleMol = i;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, sorry.
You could perhaps use drawMols_.size()-1 here rather than carrying j around. It might be a bit more immediately obvious what the intention was.
Although you probably need to change the lines just above that where it updates the rows and columns to also use j, in which case ignore the bit above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DavidACosgrove Thanks for your review, I think it is a good idea and I have made the change you suggested.

Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

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

LGTM

@greglandrum greglandrum added the bug label Sep 6, 2022
@greglandrum greglandrum modified the milestones: 2022_09_1, 2022_03_6 Sep 6, 2022
@greglandrum greglandrum merged commit 22e99f5 into rdkit:master Sep 6, 2022
e-kwsm pushed a commit to e-kwsm/rdkit that referenced this pull request Dec 8, 2022
…5503)

* MolDraw2D::drawMolecules() should not crash on null molecules

* changes in response to review

Co-authored-by: Tosco, Paolo <paolo.tosco@novartis.com>
e-kwsm pushed a commit to e-kwsm/rdkit that referenced this pull request Dec 21, 2022
…5503)

* MolDraw2D::drawMolecules() should not crash on null molecules

* changes in response to review

Co-authored-by: Tosco, Paolo <paolo.tosco@novartis.com>
e-kwsm pushed a commit to e-kwsm/rdkit that referenced this pull request Jun 27, 2023
…5503)

* MolDraw2D::drawMolecules() should not crash on null molecules

* changes in response to review

Co-authored-by: Tosco, Paolo <paolo.tosco@novartis.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants