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

do not recommend to make string immutable #1639

Merged
merged 3 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions slither/detectors/variables/unchanged_state_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ def detect(self):
self.constant_candidates.append(v)

elif (
v in constructor_variables_written or v in variables_initialized
) and version.parse(self.compilation_unit.solc_version) >= version.parse(
"0.6.5"
not v.type.is_dynamic
and version.parse(self.compilation_unit.solc_version)
>= version.parse("0.6.5")
and (v in constructor_variables_written or v in variables_initialized)
):
self.immutable_candidates.append(v)
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ contract MyConc{
uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number;
uint not_constant_5;
string cannote_be_immutable;

constructor(uint b) public {
constructor(uint b, string memory c) public {
not_constant_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ contract MyConc{
uint not_constant_2 = getNumber();
uint not_constant_3 = 10 + block.number;
uint not_constant_5;
string cannote_be_immutable;

constructor(uint b) public {
constructor(uint b, string memory c) public {
not_constant_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ contract Good {
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
string cannote_be_immutable;

constructor(uint b) public {
constructor(uint b, string memory c) public {
should_be_immutable_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ contract Good {
uint immutable should_be_immutable_3 = 10 + block.number;
B immutable should_be_immutable_4 = new B();
uint immutable should_be_immutable_5;
string cannote_be_immutable;

constructor(uint b) {
constructor(uint b, string memory c) {
should_be_immutable_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ contract Bad {
uint should_be_immutable_2 = getNumber();
uint should_be_immutable_3 = 10 + block.number;
uint should_be_immutable_5;
string cannote_be_immutable;

constructor(uint b) {
constructor(uint b, string memory c) {
should_be_immutable_5 = b;
cannote_be_immutable = c;
}

function getNumber() public returns(uint){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
Expand All @@ -49,7 +49,9 @@
53,
54,
55,
56
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
Expand Down Expand Up @@ -90,7 +92,7 @@
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
Expand All @@ -115,7 +117,9 @@
53,
54,
55,
56
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
Expand Down Expand Up @@ -156,7 +160,7 @@
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
Expand All @@ -181,7 +185,9 @@
53,
54,
55,
56
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
Expand Down Expand Up @@ -222,7 +228,7 @@
"name": "Bad",
"source_mapping": {
"start": 718,
"length": 493,
"length": 577,
"filename_relative": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/immutable-states/0.8.0/immut_state_variables.sol",
Expand All @@ -247,7 +253,9 @@
53,
54,
55,
56
56,
57,
58
],
"starting_column": 1,
"ending_column": 2
Expand Down