Fix crash when passing empty strings to bytes.concat()

This commit is contained in:
Kamil Śliwak 2021-06-25 20:48:34 +02:00
parent 7bce83e7c4
commit fa3696878b
6 changed files with 36 additions and 2 deletions

View File

@ -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.

View File

@ -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))

View File

@ -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))

View File

@ -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"

View File

@ -0,0 +1,6 @@
contract C {
function f() public pure {
bytes.concat(hex"", unicode"", "");
}
}
// ----