Skip to content

[Add Detector]: Suspicious Self Assignment#57

Open
jes16jupyter wants to merge 3 commits intoPicodes:mainfrom
jes16jupyter:main
Open

[Add Detector]: Suspicious Self Assignment#57
jes16jupyter wants to merge 3 commits intoPicodes:mainfrom
jes16jupyter:main

Conversation

@jes16jupyter
Copy link
Copy Markdown

A self-assignment occurs when a variable or state is assigned a value that is already held by that variable or state itself. This situation often indicates a potential issue in the code, which can be redundant or incorrect. Specifically, self-assignment might suggest that the value assignment does not change the state of the variable, or it could be a sign of a logical error.

Test:

    function dota(address val) public {
        uint x = 1;
        val = val; // catch
        map[val] = map[val]; // catch
        uint[] memory abc = new uint[](2);
        abc[0] = abc[0]; // catch
        abc[x] = abc[x]; // catch
        abc[0] = abc[x];
        map2[val][val] = map2[val][val]; // catch
        map2[val][val] = map2[val][address(0)];
    }

@jes16jupyter
Copy link
Copy Markdown
Author

Hi @Picodes this is a detector to detect potential typo and incorrect value assignment.

@jes16jupyter
Copy link
Copy Markdown
Author

Hi @Picodes any updates?

rzpbcodes

This comment was marked as resolved.

rzpbcodes

This comment was marked as resolved.

Copy link
Copy Markdown

@rzpbcodes rzpbcodes left a comment

Choose a reason for hiding this comment

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

approving new detector.

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