Skip to content

Commit

Permalink
Fix segmentation fault when resolving to empty left hand side tuple-type
Browse files Browse the repository at this point in the history
  • Loading branch information
r0qs committed May 10, 2024
1 parent 5091b5b commit 0646e8f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Bugfixes:
* SMTChecker: Fix internal error when using bitwise operators with an array element as argument.
* Standard JSON Interface: Fix ICE when the optimizer is disabled and an empty/blank string is used for ``optimizerSteps`` sequence.
* StaticAnalyzer: Only raise a compile time error for division and modulo by zero when it's between literals.
* TypeChecker: Fix segmentation fault when assigning to complex left side tuple expression that resolves to empty.
* Yul Optimizer: Fix the order of assignments generated by ``SSATransform`` being dependent on AST IDs, sometimes resulting in different (but equivalent) bytecode when unrelated files were added to the compilation pipeline.


Expand Down
3 changes: 2 additions & 1 deletion libsolidity/analysis/TypeChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ void TypeChecker::checkDoubleStorageAssignment(Assignment const& _assignment)
TupleType const& lhsType = dynamic_cast<TupleType const&>(*type(_lhs));
TupleExpression const* lhsResolved = dynamic_cast<TupleExpression const*>(resolveOuterUnaryTuples(&_lhs));

if (lhsType.components().size() != _rhs.components().size() || lhsResolved->components().size() != _rhs.components().size())
solAssert(!lhsResolved || lhsResolved->components().size() == lhsType.components().size());
if (lhsType.components().size() != _rhs.components().size())
{
solAssert(m_errorReporter.hasErrors(), "");
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
contract C {
uint[] public array;

function f() public {
(f()) = ();
}

function g() public {
(revert()) = ();
}

function h() internal returns (uint, uint) {}

function i() public {
(h()) = (1, 1);
}

function j() public returns (uint, uint) {
(j()) = (1, 1);
}

function m() public {
(uint x, uint y) = (1, 1); // OK
}

function n() public {
((array.push(), array.push())) = (1, 1); // OK
}
}
// ----
// TypeError 4247: (62-65): Expression has to be an lvalue.
// TypeError 4247: (103-111): Expression has to be an lvalue.
// TypeError 4247: (197-200): Expression has to be an lvalue.
// TypeError 4247: (263-266): Expression has to be an lvalue.

0 comments on commit 0646e8f

Please sign in to comment.