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

[BUG] DivExpression problem on division by 0 #65

Closed
britzl opened this issue Jun 29, 2022 · 0 comments · Fixed by #70
Closed

[BUG] DivExpression problem on division by 0 #65

britzl opened this issue Jun 29, 2022 · 0 comments · Fixed by #70
Labels
bug Something isn't working waiting for release The issue has been fixed, but the fix is not included in the current release.

Comments

@britzl
Copy link
Contributor

britzl commented Jun 29, 2022

Describe the bug
The DivExpression in ast.lua has a simplify argument which will perform the division and store the result if both left and right-hand side of the expression is a constant. This works great in all cases except when dividing by 0.

print(1/0) -- inf
print(-1/0) -- -inf
print(0/0) -- nan

The above three expressions return constants inf and nan of type number. The problem when simplifying this is that the resulting string will become:

print(inf) -- nil
print(-inf) -- attempt to perform arithmetic on global 'inf' (a nil value)
print(nan) -- nil

Expected behavior
The DivExpression should not simplify the expression when the right hand side is 0.

To Reproduce
Steps to reproduce the behavior:

  • Create a file divexpression.lua containing print(-1/0)
  • Run lua cli.lua --preset Weak divexpression.lua

Observe divexpression.obfuscated.lua

@britzl britzl added the bug Something isn't working label Jun 29, 2022
@levno-710 levno-710 added the waiting for release The issue has been fixed, but the fix is not included in the current release. label Jun 29, 2022
@levno-710 levno-710 mentioned this issue Jul 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting for release The issue has been fixed, but the fix is not included in the current release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants