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

Integer overflow when parsing atom count in molecular formula #734

Closed
wants to merge 1 commit into from

Conversation

oatkachenko
Copy link

No description provided.

@johnmay
Copy link
Member

johnmay commented Jun 3, 2021

It's the way it is for speed, I don't think the solution of using the slower API call and catching the exception is better, you still end up with a negative number. Nicer would be to just check if the value overflows

@oatkachenko
Copy link
Author

I have replaced API call with manual overflow checking.


@Test public void atomCountIsSafeForOverflow() {
// max integer
assertFormulaContainsExactlyAtoms(getMolecularFormula("H2147483647", builder), Integer.MAX_VALUE);
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this test. Should there not 2147483647 atoms here?

Copy link
Member

Choose a reason for hiding this comment

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

2147483647 is Interger.MAX

@johnmay
Copy link
Member

johnmay commented Jan 30, 2022

Looking back at this I think the simpler solution is to cap the atom count at some upper limit (e.g. 1 million) which is more than enough. TITIN is 35k amino acids https://en.wikipedia.org/wiki/Titin

johnmay added a commit that referenced this pull request Jan 30, 2022
@johnmay
Copy link
Member

johnmay commented Jan 30, 2022

Now #808

@johnmay johnmay closed this Jan 30, 2022
egonw pushed a commit that referenced this pull request Jan 30, 2022
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.

None yet

3 participants