aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-09-22 21:41:17 +0800
committerchriseth <c@ethdev.com>2015-09-22 21:41:17 +0800
commit5ca79f005e265b18d2dc8a9dd37c4c38acb952fd (patch)
tree611bdc88260d63fc63a6a5ec977ffd16b79db38f
parent352c196eb37744b8054909a9801d55c672d0eb1c (diff)
parented76798406f387c8bd138ed22cd0b1687a79fa32 (diff)
downloaddexon-solidity-5ca79f005e265b18d2dc8a9dd37c4c38acb952fd.tar.gz
dexon-solidity-5ca79f005e265b18d2dc8a9dd37c4c38acb952fd.tar.zst
dexon-solidity-5ca79f005e265b18d2dc8a9dd37c4c38acb952fd.zip
Merge pull request #81 from LianaHus/sol_strings_in_struct
Sol strings in struct
-rw-r--r--libsolidity/AST.h9
-rw-r--r--libsolidity/ExpressionCompiler.cpp2
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp42
3 files changed, 49 insertions, 4 deletions
diff --git a/libsolidity/AST.h b/libsolidity/AST.h
index de0ef3ef..ba529a8a 100644
--- a/libsolidity/AST.h
+++ b/libsolidity/AST.h
@@ -347,10 +347,13 @@ private:
class StructDefinition: public Declaration
{
public:
- StructDefinition(SourceLocation const& _location,
- ASTPointer<ASTString> const& _name,
- std::vector<ASTPointer<VariableDeclaration>> const& _members):
+ StructDefinition(
+ SourceLocation const& _location,
+ ASTPointer<ASTString> const& _name,
+ std::vector<ASTPointer<VariableDeclaration>> const& _members
+ ):
Declaration(_location, _name), m_members(_members) {}
+
virtual void accept(ASTVisitor& _visitor) override;
virtual void accept(ASTConstVisitor& _visitor) const override;
diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp
index 1b9f2150..7db0dde9 100644
--- a/libsolidity/ExpressionCompiler.cpp
+++ b/libsolidity/ExpressionCompiler.cpp
@@ -390,7 +390,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall)
TypeType const& type = dynamic_cast<TypeType const&>(*_functionCall.expression().type());
auto const& structType = dynamic_cast<StructType const&>(*type.actualType());
- m_context << u256(max(32u, structType.calldataEncodedSize(true)));
+ m_context << max(u256(32u), structType.memorySize());
utils().allocateMemory();
m_context << eth::Instruction::DUP1;
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 9c4d0c5b..98da1e27 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -5283,6 +5283,48 @@ BOOST_AUTO_TEST_CASE(simple_throw)
BOOST_CHECK(callContractFunction("f(uint256)", u256(1)) == encodeArgs());
}
+BOOST_AUTO_TEST_CASE(strings_in_struct)
+{
+ char const* sourceCode = R"(
+ contract buggystruct {
+ Buggy public bug;
+
+ struct Buggy {
+ uint first;
+ uint second;
+ uint third;
+ string last;
+ }
+
+ function buggystruct(){
+ bug = Buggy(10, 20, 30, "asdfghjkl");
+ }
+ function getFirst() returns (uint)
+ {
+ return bug.first;
+ }
+ function getSecond() returns (uint)
+ {
+ return bug.second;
+ }
+ function getThird() returns (uint)
+ {
+ return bug.third;
+ }
+ function getLast() returns (string)
+ {
+ return bug.last;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ string s = "asdfghjkl";
+ BOOST_CHECK(callContractFunction("getFirst()") == encodeArgs(u256(10)));
+ BOOST_CHECK(callContractFunction("getSecond()") == encodeArgs(u256(20)));
+ BOOST_CHECK(callContractFunction("getThird()") == encodeArgs(u256(30)));
+ BOOST_CHECK(callContractFunction("getLast()") == encodeDyn(s));
+}
+
BOOST_AUTO_TEST_SUITE_END()
}