diff --git a/slither/detectors/variables/uninitialized_local_variables.py b/slither/detectors/variables/uninitialized_local_variables.py index 3f7eee4d6d..0aa5579f88 100644 --- a/slither/detectors/variables/uninitialized_local_variables.py +++ b/slither/detectors/variables/uninitialized_local_variables.py @@ -70,7 +70,8 @@ def _detect_uninitialized( and len(node.sons) == 1 # Should always be true for a node that has a STARTLOOP son and node.sons[0].type == NodeType.STARTLOOP ): - fathers_context.remove(node.variable_declaration) + 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] diff --git a/tests/e2e/detectors/test_data/uninitialized-local/0.4.25/uninitialized_local_variable.sol b/tests/e2e/detectors/test_data/uninitialized-local/0.4.25/uninitialized_local_variable.sol index 82a3ab1246..37d4650e23 100644 --- a/tests/e2e/detectors/test_data/uninitialized-local/0.4.25/uninitialized_local_variable.sol +++ b/tests/e2e/detectors/test_data/uninitialized-local/0.4.25/uninitialized_local_variable.sol @@ -10,6 +10,11 @@ contract Uninitialized{ for(uint i; i < 6; i++) { uint a = i; } + + for(uint j = 0; j < 6; j++) { + uint b = j; + } + } } diff --git a/tests/e2e/detectors/test_data/uninitialized-local/0.4.25/uninitialized_local_variable.sol-0.4.25.zip b/tests/e2e/detectors/test_data/uninitialized-local/0.4.25/uninitialized_local_variable.sol-0.4.25.zip index 2c4ccdf173..29db479d57 100644 Binary files a/tests/e2e/detectors/test_data/uninitialized-local/0.4.25/uninitialized_local_variable.sol-0.4.25.zip and b/tests/e2e/detectors/test_data/uninitialized-local/0.4.25/uninitialized_local_variable.sol-0.4.25.zip differ diff --git a/tests/e2e/detectors/test_data/uninitialized-local/0.5.16/uninitialized_local_variable.sol b/tests/e2e/detectors/test_data/uninitialized-local/0.5.16/uninitialized_local_variable.sol index 82a3ab1246..37d4650e23 100644 --- a/tests/e2e/detectors/test_data/uninitialized-local/0.5.16/uninitialized_local_variable.sol +++ b/tests/e2e/detectors/test_data/uninitialized-local/0.5.16/uninitialized_local_variable.sol @@ -10,6 +10,11 @@ contract Uninitialized{ for(uint i; i < 6; i++) { uint a = i; } + + for(uint j = 0; j < 6; j++) { + uint b = j; + } + } } diff --git a/tests/e2e/detectors/test_data/uninitialized-local/0.5.16/uninitialized_local_variable.sol-0.5.16.zip b/tests/e2e/detectors/test_data/uninitialized-local/0.5.16/uninitialized_local_variable.sol-0.5.16.zip index b29fe8a42a..24782d0217 100644 Binary files a/tests/e2e/detectors/test_data/uninitialized-local/0.5.16/uninitialized_local_variable.sol-0.5.16.zip and b/tests/e2e/detectors/test_data/uninitialized-local/0.5.16/uninitialized_local_variable.sol-0.5.16.zip differ diff --git a/tests/e2e/detectors/test_data/uninitialized-local/0.6.11/uninitialized_local_variable.sol b/tests/e2e/detectors/test_data/uninitialized-local/0.6.11/uninitialized_local_variable.sol index 82a3ab1246..37d4650e23 100644 --- a/tests/e2e/detectors/test_data/uninitialized-local/0.6.11/uninitialized_local_variable.sol +++ b/tests/e2e/detectors/test_data/uninitialized-local/0.6.11/uninitialized_local_variable.sol @@ -10,6 +10,11 @@ contract Uninitialized{ for(uint i; i < 6; i++) { uint a = i; } + + for(uint j = 0; j < 6; j++) { + uint b = j; + } + } } diff --git a/tests/e2e/detectors/test_data/uninitialized-local/0.6.11/uninitialized_local_variable.sol-0.6.11.zip b/tests/e2e/detectors/test_data/uninitialized-local/0.6.11/uninitialized_local_variable.sol-0.6.11.zip index 793b30f4a1..d1ac3a5ab8 100644 Binary files a/tests/e2e/detectors/test_data/uninitialized-local/0.6.11/uninitialized_local_variable.sol-0.6.11.zip and b/tests/e2e/detectors/test_data/uninitialized-local/0.6.11/uninitialized_local_variable.sol-0.6.11.zip differ diff --git a/tests/e2e/detectors/test_data/uninitialized-local/0.7.6/uninitialized_local_variable.sol b/tests/e2e/detectors/test_data/uninitialized-local/0.7.6/uninitialized_local_variable.sol index 82a3ab1246..37d4650e23 100644 --- a/tests/e2e/detectors/test_data/uninitialized-local/0.7.6/uninitialized_local_variable.sol +++ b/tests/e2e/detectors/test_data/uninitialized-local/0.7.6/uninitialized_local_variable.sol @@ -10,6 +10,11 @@ contract Uninitialized{ for(uint i; i < 6; i++) { uint a = i; } + + for(uint j = 0; j < 6; j++) { + uint b = j; + } + } } diff --git a/tests/e2e/detectors/test_data/uninitialized-local/0.7.6/uninitialized_local_variable.sol-0.7.6.zip b/tests/e2e/detectors/test_data/uninitialized-local/0.7.6/uninitialized_local_variable.sol-0.7.6.zip index 6aa5401d17..eaef1050dd 100644 Binary files a/tests/e2e/detectors/test_data/uninitialized-local/0.7.6/uninitialized_local_variable.sol-0.7.6.zip and b/tests/e2e/detectors/test_data/uninitialized-local/0.7.6/uninitialized_local_variable.sol-0.7.6.zip differ