Comments (1)
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
.
from sonarjs.
Related Issues (20)
- update all (easy) dependencies and evaluate upgrading hard ones
- Create artifact which embeds Node.JS for Alpine Linux HOT 1
- FP S6827: Thymeleaf `th:text` attribute is not recognized as a content HOT 1
- Do not count LOCs for CSS files indexed as test files
- Exclude assignment expressions to `require()` from copy-paste detection HOT 1
- javascript/S6654.html is missing `Of` in references to prototype getter/setter methods of Object
- Fix FP S6754 (`hook-use-state`): Ignore state variables without a setter
- Fix FP S2699 (`assertions-in-tests`): Add support for `supertest` HOT 1
- Fix FP S6747 (`no-unknown-property`): Don't raise for `css` attribute HOT 1
- Fix FP S6747 (`no-unknown-property`): Don't raise for allowed attributes HOT 1
- Fix FP S6747 (`no-unknown-property`): Don't raise issues from `eslint-plugin-react/no-unknown-property` when react is not used HOT 1
- Embedded Node.js runtime: detect the host architecture correctly in MacOS JRE Intel virtualization HOT 1
- Fix FP S6754 (`hook-use-state`): Add exception when using `useState` for components HOT 1
- Embedded Node.js: when `sonar.nodejs.forceHost` is set, do not deploy the runtime HOT 1
- Remove usage of deprecated logging APIs
- JS-18 S6819 False Positive when using SAP UI5 React components HOT 1
- Use 18.17.0 as minimum version for Node.JS
- Ignore runtime errors when saving cpd tokens
- Incorrect S6757 Error for Class Components HOT 8
- We should skip the whole file when we fail to save CPD token
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonarjs.