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

LoopsShouldNotBeInfiniteCheck: infinite loop #624

Closed
vilchik-elena opened this issue Jul 27, 2017 · 1 comment
Closed

LoopsShouldNotBeInfiniteCheck: infinite loop #624

vilchik-elena opened this issue Jul 27, 2017 · 1 comment
Assignees
Labels
type: bug Exceptions and blocking issues during analysis
Milestone

Comments

@vilchik-elena
Copy link
Contributor

vilchik-elena commented Jul 27, 2017

function foo() {
    for (let x=0 ; ; ) {       // makes rule to run infinitely
    }
}
@vilchik-elena vilchik-elena added type: bug Exceptions and blocking issues during analysis rule labels Jul 27, 2017
@vilchik-elena vilchik-elena added this to the 3.2 milestone Jul 27, 2017
@inverno
Copy link
Contributor

inverno commented Jul 27, 2017

Had a look into this, the source of the problem is the CFG. In JsCfgBlock we have the following code :
:

  JsCfgBlock skipEmptyBlocks() {
    JsCfgBlock block = this;
    while (block.successors().size() == 1 && block.elements().isEmpty()) {
      block = (JsCfgBlock) block.successors().iterator().next();
    }
    return block;
  }

This will be an infinite loop if the block is part of a loop of blocks (which is the case with infinite loops) and each block in that loop has zero elements (as it is the case for an empty for loop with no condition and no update expression).

The reason why this happens only when an initializer is present is because in ControlFlowGraphBuilder.visitForStatement when both the initializer, the condition, and the loop body are empty, we add the for keyword as an element in the loop body block, thus accidentally avoiding the infinite loop.

    if (tree.init() != null) {
      buildExpression(tree.init());
    } else if (tree.condition() == null && loopBodyBlock.elements().isEmpty()) {
      loopBodyBlock.addElement(tree.forKeyword());
    }

We probably need to make this second part more coherent along with the actual fix in JsCfgBlock.

@inverno inverno added ready and removed in progress labels Sep 26, 2017
@ghost ghost assigned inverno Sep 28, 2017
@ghost ghost removed the review label Sep 28, 2017
@vilchik-elena vilchik-elena added type: false positive Issue is reported when it should NOT be and removed type: false positive Issue is reported when it should NOT be labels Sep 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Exceptions and blocking issues during analysis
Projects
None yet
Development

No branches or pull requests

2 participants