mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #11581 from ethereum/fix-crash-on-empty-string-in-bytes-concat
Fix `bytes.concat("")`
This commit is contained in:
commit
ccad22bafa
@ -10,6 +10,7 @@ Compiler Features:
|
||||
|
||||
|
||||
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 passing zero to ``bytes.concat()``.
|
||||
* 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);
|
||||
else if (
|
||||
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())));
|
||||
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);
|
||||
else if (
|
||||
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())));
|
||||
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