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

uninitialized-local don't report variable in loop header #1911

Merged
merged 2 commits into from
May 16, 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
11 changes: 10 additions & 1 deletion slither/detectors/variables/uninitialized_local_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
from typing import List

from slither.core.cfg.node import Node
from slither.core.cfg.node import Node, NodeType
from slither.core.declarations.function_contract import FunctionContract
from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
from slither.utils.output import Output
Expand Down Expand Up @@ -64,6 +64,15 @@ def _detect_uninitialized(

self.visited_all_paths[node] = list(set(self.visited_all_paths[node] + fathers_context))

# Remove a local variable declared in a for loop header
if (
node.type == NodeType.VARIABLE
and len(node.sons) == 1 # Should always be true for a node that has a STARTLOOP son
and node.sons[0].type == NodeType.STARTLOOP
):
if node.variable_declaration in fathers_context:
fathers_context.remove(node.variable_declaration)

if self.key in node.context:
fathers_context += node.context[self.key]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ contract Uninitialized{
return uint_not_init + uint_init;
}

function noreportfor() public {
for(uint i; i < 6; i++) {
uint a = i;
}

for(uint j = 0; j < 6; j++) {
uint b = j;
}

}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ contract Uninitialized{
return uint_not_init + uint_init;
}

function noreportfor() public {
for(uint i; i < 6; i++) {
uint a = i;
}

for(uint j = 0; j < 6; j++) {
uint b = j;
}

}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ contract Uninitialized{
return uint_not_init + uint_init;
}

function noreportfor() public {
for(uint i; i < 6; i++) {
uint a = i;
}

for(uint j = 0; j < 6; j++) {
uint b = j;
}

}

}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ contract Uninitialized{
return uint_not_init + uint_init;
}

function noreportfor() public {
for(uint i; i < 6; i++) {
uint a = i;
}

for(uint j = 0; j < 6; j++) {
uint b = j;
}

}

}
Binary file not shown.