Skip to content

Commit

Permalink
Merge pull request #1911 from crytic/dev-uninitialized-local-for
Browse files Browse the repository at this point in the history
uninitialized-local don't report variable in loop header
  • Loading branch information
montyly authored May 16, 2023
2 parents 6388f98 + 408c863 commit 5917de9
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 1 deletion.
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.

0 comments on commit 5917de9

Please sign in to comment.