Skip to content

[BUG] DivExpression problem on division by 0 #65

@britzl

Description

@britzl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwaiting for releaseThe issue has been fixed, but the fix is not included in the current release.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions