mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix crash when passing empty strings to bytes.concat()
This commit is contained in:
parent
7bce83e7c4
commit
fa3696878b
@ -10,6 +10,7 @@ Compiler Features:
|
|||||||
|
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
* Code Generator: Fix crash when passing an empty string literal to ``bytes.concat()``.
|
||||||
* Code Generator: Fix internal compiler error when calling functions bound to calldata structs and arrays.
|
* Code Generator: Fix internal compiler error when calling functions bound to calldata structs and arrays.
|
||||||
* Code Generator: Fix internal compiler error when passing zero to ``bytes.concat()``.
|
* Code Generator: Fix internal compiler error when passing zero to ``bytes.concat()``.
|
||||||
* Type Checker: Fix internal error and prevent static calls to unimplemented modifiers.
|
* Type Checker: Fix internal error and prevent static calls to unimplemented modifiers.
|
||||||
|
@ -1083,7 +1083,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
|
|||||||
targetTypes.emplace_back(argument->annotation().type);
|
targetTypes.emplace_back(argument->annotation().type);
|
||||||
else if (
|
else if (
|
||||||
auto const* literalType = dynamic_cast<StringLiteralType const*>(argument->annotation().type);
|
auto const* literalType = dynamic_cast<StringLiteralType const*>(argument->annotation().type);
|
||||||
literalType && literalType->value().size() <= 32
|
literalType && !literalType->value().empty() && literalType->value().size() <= 32
|
||||||
)
|
)
|
||||||
targetTypes.emplace_back(TypeProvider::fixedBytes(static_cast<unsigned>(literalType->value().size())));
|
targetTypes.emplace_back(TypeProvider::fixedBytes(static_cast<unsigned>(literalType->value().size())));
|
||||||
else if (auto const* literalType = dynamic_cast<RationalNumberType const*>(argument->annotation().type))
|
else if (auto const* literalType = dynamic_cast<RationalNumberType const*>(argument->annotation().type))
|
||||||
|
@ -2473,7 +2473,7 @@ string YulUtilFunctions::bytesConcatFunction(vector<Type const*> const& _argumen
|
|||||||
targetTypes.emplace_back(argumentType);
|
targetTypes.emplace_back(argumentType);
|
||||||
else if (
|
else if (
|
||||||
auto const* literalType = dynamic_cast<StringLiteralType const*>(argumentType);
|
auto const* literalType = dynamic_cast<StringLiteralType const*>(argumentType);
|
||||||
literalType && literalType->value().size() <= 32
|
literalType && !literalType->value().empty() && literalType->value().size() <= 32
|
||||||
)
|
)
|
||||||
targetTypes.emplace_back(TypeProvider::fixedBytes(static_cast<unsigned>(literalType->value().size())));
|
targetTypes.emplace_back(TypeProvider::fixedBytes(static_cast<unsigned>(literalType->value().size())));
|
||||||
else if (auto const* literalType = dynamic_cast<RationalNumberType const*>(argumentType))
|
else if (auto const* literalType = dynamic_cast<RationalNumberType const*>(argumentType))
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public returns (bytes memory) {
|
||||||
|
bytes memory b = "";
|
||||||
|
return bytes.concat(
|
||||||
|
bytes.concat(b),
|
||||||
|
bytes.concat(b, b),
|
||||||
|
bytes.concat("", b),
|
||||||
|
bytes.concat(b, "")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function g() public returns (bytes memory) {
|
||||||
|
return bytes.concat("", "abc", hex"", "abc", unicode"");
|
||||||
|
}
|
||||||
|
|
||||||
|
function h() public returns (bytes memory) {
|
||||||
|
bytes memory b = "";
|
||||||
|
return bytes.concat(b, "abc", b, "abc", b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ====
|
||||||
|
// compileToEwasm: also
|
||||||
|
// compileViaYul: also
|
||||||
|
// ----
|
||||||
|
// f() -> 0x20, 0
|
||||||
|
// g() -> 0x20, 6, "abcabc"
|
||||||
|
// h() -> 0x20, 6, "abcabc"
|
@ -0,0 +1,6 @@
|
|||||||
|
contract C {
|
||||||
|
function f() public pure {
|
||||||
|
bytes.concat(hex"", unicode"", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
Loading…
Reference in New Issue
Block a user