Merge pull request #1650 from crytic/ternary-func-arg

fix ternary in nested expr with index access
pull/1691/head
Feist Josselin 2 years ago committed by GitHub
commit 80528995b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      slither/utils/expression_manipulations.py
  2. 10
      tests/slithir/ternary_expressions.sol

@ -98,11 +98,13 @@ class SplitTernaryExpression:
if isinstance( if isinstance(
expression, expression,
(Literal, Identifier, IndexAccess, NewArray, NewContract, ElementaryTypeNameExpression), (Literal, Identifier, NewArray, NewContract, ElementaryTypeNameExpression),
): ):
return return
if isinstance(expression, (AssignmentOperation, BinaryOperation, TupleExpression)): if isinstance(
expression, (AssignmentOperation, BinaryOperation, TupleExpression, IndexAccess)
):
true_expression._expressions = [] true_expression._expressions = []
false_expression._expressions = [] false_expression._expressions = []
self.convert_expressions(expression, true_expression, false_expression) self.convert_expressions(expression, true_expression, false_expression)
@ -137,8 +139,6 @@ class SplitTernaryExpression:
# TODO: can we get rid of `NoneType` expressions in `TupleExpression`? # TODO: can we get rid of `NoneType` expressions in `TupleExpression`?
# montyly: this might happen with unnamed tuple (ex: (,,,) = f()), but it needs to be checked # montyly: this might happen with unnamed tuple (ex: (,,,) = f()), but it needs to be checked
if next_expr: if next_expr:
if isinstance(next_expr, IndexAccess):
self.convert_index_access(next_expr, true_expression, false_expression)
if self.conditional_not_ahead( if self.conditional_not_ahead(
next_expr, true_expression, false_expression, f_expressions next_expr, true_expression, false_expression, f_expressions

@ -39,4 +39,14 @@ contract C {
function g(address one) public { function g(address one) public {
(, uint x) = Test(one).testTuple(); (, uint x) = Test(one).testTuple();
} }
uint[] myIntegers;
function _h(uint c) internal returns(uint) {
return c;
}
function h(bool cond, uint a, uint b) public {
uint d = _h(
myIntegers[cond ? a : b]
);
}
} }

Loading…
Cancel
Save