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 addition/subtraction leading to an overflow is not converted to Number #1088

Closed
conicgames opened this issue Feb 15, 2022 · 2 comments · Fixed by #1091
Closed

Integer addition/subtraction leading to an overflow is not converted to Number #1088

conicgames opened this issue Feb 15, 2022 · 2 comments · Fixed by #1091

Comments

@conicgames
Copy link
Contributor

conicgames commented Feb 15, 2022

Hello,

The following code doesn't behave as expected:

var result = new Jint.Engine().Evaluate("2147483647 + 1");
// Actual: 'result' is of type Integer with value -2147483648
// Expected: 'result' would be of type Number with value 2147483648

Subtraction has a similar behaviour.

Thanks for your time.

@conicgames
Copy link
Contributor Author

I'll take care of the fix and make a pull request. As I understood, both operations should follow the same pattern as the multiplication operator: cast the first operand to long before the operation in JintBinaryExpression.cs at lines 271 and 318. I'm just not sure where to put the unit test. I'll try to figure it out.

@conicgames conicgames changed the title Interger addition leading to an overflow is not converted to Number Integer addition/subtraction leading to an overflow is not converted to Number Feb 16, 2022
@lahma
Copy link
Collaborator

lahma commented Feb 16, 2022

Great find! The unit test location isn't that big of a deal than what's to have one. EngineTests maybe is a general thow-it-all file.

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 a pull request may close this issue.

2 participants