Skip to content

SONARPY-471 Rule S2190: Recursion should not be infinite#461

Merged
andrea-guarino-sonarsource merged 6 commits into
masterfrom
SONARPY-471
Nov 4, 2019
Merged

SONARPY-471 Rule S2190: Recursion should not be infinite#461
andrea-guarino-sonarsource merged 6 commits into
masterfrom
SONARPY-471

Conversation

@alban-auzeill

Copy link
Copy Markdown
Member

No description provided.

@alban-auzeill alban-auzeill force-pushed the SONARPY-471 branch 2 times, most recently from b974811 to f2cdd92 Compare November 1, 2019 18:48
@alban-auzeill alban-auzeill marked this pull request as ready for review November 1, 2019 19:10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test case in CheckUtilsTest for this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: could you please add newline here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add a test case to document the following FN:

def f(p):
  return f(p) if p else f(p) # FN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could add a test case to document the following FN:

def fn():
  if fn() or x == 10:
     ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nop, there's no FN, visitBinaryExpression always takes into account leftOperand() recursion, even for or and and.
I added the following test:

def fun21(x): # Noncompliant
    if fun21(x + 1) or x == 10:
        print(2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not very clear to me why we're excluding for statements. Is it for a limitation in the CFG? In that case, please create a ticket for it and document in the unit tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, I think it's useless. It was probably useful before I exclude lambda or sub-function, but it was not the right workaround. So I removed this visitForStatement and added more test related to for.

@andrea-guarino-sonarsource andrea-guarino-sonarsource merged commit 9f48b74 into master Nov 4, 2019
@andrea-guarino-sonarsource andrea-guarino-sonarsource deleted the SONARPY-471 branch November 4, 2019 16:05
hashicorp-vault-sonar-prod Bot pushed a commit that referenced this pull request Aug 21, 2025
…go.db.models.Model`. (#461)

GitOrigin-RevId: 41e302fa7fcd41f7268a82e31f60e38ddd97504e
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 this pull request may close these issues.

2 participants