Skip to content

Commit 0c174ef

Browse files
authored
Merge pull request #828 from crytic/dev-remove-counter
Remove COUNTER from class
2 parents 6362982 + a988d9c commit 0c174ef

File tree

5 files changed

+136
-18
lines changed

5 files changed

+136
-18
lines changed

slither/core/slither_core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ def __init__(self):
9090

9191
self._show_ignored_findings = False
9292

93+
self.counter_slithir_tuple = 0
94+
self.counter_slithir_temporary = 0
95+
self.counter_slithir_reference = 0
96+
9397
###################################################################################
9498
###################################################################################
9599
# region Source code

slither/slithir/variables/reference.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
from typing import TYPE_CHECKING
2+
13
from slither.core.children.child_node import ChildNode
24
from slither.core.declarations import Contract, Enum, SolidityVariable, Function
35
from slither.core.variables.variable import Variable
46

7+
if TYPE_CHECKING:
8+
from slither.core.cfg.node import Node
59

6-
class ReferenceVariable(ChildNode, Variable):
7-
8-
COUNTER = 0
910

10-
def __init__(self, node, index=None):
11+
class ReferenceVariable(ChildNode, Variable):
12+
def __init__(self, node: "Node", index=None):
1113
super().__init__()
1214
if index is None:
13-
self._index = ReferenceVariable.COUNTER
14-
ReferenceVariable.COUNTER += 1
15+
self._index = node.slither.counter_slithir_reference
16+
node.slither.counter_slithir_reference += 1
1517
else:
1618
self._index = index
1719
self._points_to = None

slither/slithir/variables/temporary.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
from typing import TYPE_CHECKING
2+
13
from slither.core.children.child_node import ChildNode
24
from slither.core.variables.variable import Variable
35

6+
if TYPE_CHECKING:
7+
from slither.core.cfg.node import Node
48

5-
class TemporaryVariable(ChildNode, Variable):
6-
7-
COUNTER = 0
89

9-
def __init__(self, node, index=None):
10+
class TemporaryVariable(ChildNode, Variable):
11+
def __init__(self, node: "Node", index=None):
1012
super().__init__()
1113
if index is None:
12-
self._index = TemporaryVariable.COUNTER
13-
TemporaryVariable.COUNTER += 1
14+
self._index = node.slither.counter_slithir_temporary
15+
node.slither.counter_slithir_temporary += 1
1416
else:
1517
self._index = index
1618
self._node = node

slither/slithir/variables/tuple.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1+
from typing import TYPE_CHECKING
2+
13
from slither.core.children.child_node import ChildNode
24
from slither.slithir.variables.variable import SlithIRVariable
35

6+
if TYPE_CHECKING:
7+
from slither.core.cfg.node import Node
48

5-
class TupleVariable(ChildNode, SlithIRVariable):
6-
7-
COUNTER = 0
89

9-
def __init__(self, node, index=None):
10+
class TupleVariable(ChildNode, SlithIRVariable):
11+
def __init__(self, node: "Node", index=None):
1012
super().__init__()
1113
if index is None:
12-
self._index = TupleVariable.COUNTER
13-
TupleVariable.COUNTER += 1
14+
self._index = node.slither.counter_slithir_tuple
15+
node.slither.counter_slithir_tuple += 1
1416
else:
1517
self._index = index
1618

tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol.0.5.8.UninitializedFunctionPtrsConstructor.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,114 @@
211211
"impact": "Low",
212212
"confidence": "High"
213213
},
214+
{
215+
"elements": [
216+
{
217+
"type": "contract",
218+
"name": "bad2",
219+
"source_mapping": {
220+
"start": 483,
221+
"length": 199,
222+
"filename_used": "/GENERIC_PATH",
223+
"filename_relative": "tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol",
224+
"filename_absolute": "/GENERIC_PATH",
225+
"filename_short": "tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol",
226+
"is_dependency": false,
227+
"lines": [
228+
20,
229+
21,
230+
22,
231+
23,
232+
24,
233+
25,
234+
26,
235+
27,
236+
28,
237+
29
238+
],
239+
"starting_column": 1,
240+
"ending_column": 2
241+
}
242+
},
243+
{
244+
"type": "node",
245+
"name": "s.a(10)",
246+
"source_mapping": {
247+
"start": 668,
248+
"length": 7,
249+
"filename_used": "/GENERIC_PATH",
250+
"filename_relative": "tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol",
251+
"filename_absolute": "/GENERIC_PATH",
252+
"filename_short": "tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol",
253+
"is_dependency": false,
254+
"lines": [
255+
27
256+
],
257+
"starting_column": 5,
258+
"ending_column": 12
259+
},
260+
"type_specific_fields": {
261+
"parent": {
262+
"type": "function",
263+
"name": "constructor",
264+
"source_mapping": {
265+
"start": 625,
266+
"length": 55,
267+
"filename_used": "/GENERIC_PATH",
268+
"filename_relative": "tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol",
269+
"filename_absolute": "/GENERIC_PATH",
270+
"filename_short": "tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol",
271+
"is_dependency": false,
272+
"lines": [
273+
25,
274+
26,
275+
27,
276+
28
277+
],
278+
"starting_column": 3,
279+
"ending_column": 4
280+
},
281+
"type_specific_fields": {
282+
"parent": {
283+
"type": "contract",
284+
"name": "bad2",
285+
"source_mapping": {
286+
"start": 483,
287+
"length": 199,
288+
"filename_used": "/GENERIC_PATH",
289+
"filename_relative": "tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol",
290+
"filename_absolute": "/GENERIC_PATH",
291+
"filename_short": "tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol",
292+
"is_dependency": false,
293+
"lines": [
294+
20,
295+
21,
296+
22,
297+
23,
298+
24,
299+
25,
300+
26,
301+
27,
302+
28,
303+
29
304+
],
305+
"starting_column": 1,
306+
"ending_column": 2
307+
}
308+
},
309+
"signature": "constructor()"
310+
}
311+
}
312+
}
313+
}
314+
],
315+
"description": "Contract bad2 (tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol#20-29) \n\t s.a(10) (tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol#27) is an unintialized function pointer call in a constructor\n",
316+
"markdown": "Contract [bad2](tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol#L20-L29) \n\t [s.a(10)](tests/detectors/uninitialized-fptr-cst/uninitialized_function_ptr_constructor.sol#L27) is an unintialized function pointer call in a constructor\n",
317+
"id": "1f43b676571aff0a3ce0353dc8548e252c588f7c9248c104637d500882880134",
318+
"check": "uninitialized-fptr-cst",
319+
"impact": "Low",
320+
"confidence": "High"
321+
},
214322
{
215323
"elements": [
216324
{

0 commit comments

Comments
 (0)