Browse Source

fixed segfaults on accessing temp objects vector buffers

cl-refactor
Arkady Paronyan 10 years ago
parent
commit
c161ddb66a
  1. 3
      alethzero/MainWin.cpp
  2. 3
      libdevcore/RLP.h
  3. 20
      libdevcrypto/TrieDB.h
  4. 9
      libethereum/BlockChain.cpp
  5. 4
      libethereum/Client.cpp
  6. 20
      test/crypto.cpp

3
alethzero/MainWin.cpp

@ -109,7 +109,8 @@ Main::Main(QWidget *parent) :
cerr << "State root: " << BlockChain::genesis().stateRoot << endl;
cerr << "Block Hash: " << sha3(BlockChain::createGenesisBlock()) << endl;
cerr << "Block RLP: " << RLP(BlockChain::createGenesisBlock()) << endl;
auto block = BlockChain::createGenesisBlock();
cerr << "Block RLP: " << RLP(block) << endl;
cerr << "Block Hex: " << toHex(BlockChain::createGenesisBlock()) << endl;
cerr << "Network protocol version: " << dev::eth::c_protocolVersion << endl;
cerr << "Client database version: " << dev::eth::c_databaseVersion << endl;

3
libdevcore/RLP.h

@ -307,6 +307,9 @@ private:
mutable unsigned m_lastIndex = (unsigned)-1;
mutable unsigned m_lastEnd = 0;
mutable bytesConstRef m_lastItem;
/// Disable construction from rvalue
explicit RLP(bytes const&& _d) {}
};
/**

20
libdevcrypto/TrieDB.h

@ -553,11 +553,17 @@ template <class DB> bytes GenericTrieDB<DB>::mergeAt(RLP const& _orig, NibbleSli
auto sh = _k.shared(k);
// std::cout << _k << " sh " << k << " = " << sh << std::endl;
if (sh)
{
// shared stuff - cleve at disagreement.
return mergeAt(RLP(cleve(_orig, sh)), _k, _v, true);
auto cleved = cleve(_orig, sh);
return mergeAt(RLP(cleved), _k, _v, true);
}
else
{
// nothing shared - branch
return mergeAt(RLP(branch(_orig)), _k, _v, true);
auto branched = branch(_orig);
return mergeAt(RLP(branched), _k, _v, true);
}
}
else
{
@ -686,7 +692,10 @@ template <class DB> bytes GenericTrieDB<DB>::deleteAt(RLP const& _orig, NibbleSl
byte used = uniqueInUse(_orig, 16);
if (used != 255)
if (isTwoItemNode(_orig[used]))
return graft(RLP(merge(_orig, used)));
{
auto merged = merge(_orig, used);
return graft(RLP(merged));
}
else
return merge(_orig, used);
else
@ -722,7 +731,10 @@ template <class DB> bytes GenericTrieDB<DB>::deleteAt(RLP const& _orig, NibbleSl
// yes; merge
if (isTwoItemNode(rlp[used]))
return graft(RLP(merge(rlp, used)));
{
auto merged = merge(rlp, used);
return graft(RLP(merged));
}
else
return merge(rlp, used);
}

9
libethereum/BlockChain.cpp

@ -277,8 +277,10 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db)
auto pd = details(bi.parentHash);
if (!pd)
{
cwarn << "Odd: details is returning false despite block known:" << RLP(pd.rlp());
cwarn << "Block:" << RLP(block(bi.parentHash));
auto pdata = pd.rlp();
cwarn << "Odd: details is returning false despite block known:" << RLP(pdata);
auto parentBlock = block(bi.parentHash);
cwarn << "Block:" << RLP(parentBlock);
}
// Check it's not crazy
@ -447,7 +449,8 @@ h256Set BlockChain::allUnclesFrom(h256 _parent) const
for (unsigned i = 0; i < 6 && p != m_genesisHash; ++i, p = details(p).parent)
{
ret.insert(p); // TODO: check: should this be details(p).parent?
for (auto i: RLP(block(p))[2])
auto bl = block(p);
for (auto i: RLP(bl)[2])
ret.insert(sha3(i.data()));
}
return ret;

4
libethereum/Client.cpp

@ -36,7 +36,9 @@ using namespace p2p;
VersionChecker::VersionChecker(string const& _dbPath):
m_path(_dbPath.size() ? _dbPath : Defaults::dbPath())
{
m_ok = RLP(contents(m_path + "/protocol")).toInt<unsigned>(RLP::LaisezFaire) == c_protocolVersion && RLP(contents(m_path + "/database")).toInt<unsigned>(RLP::LaisezFaire) == c_databaseVersion;
auto protocolContents = contents(m_path + "/protocol");
auto databaseContents = contents(m_path + "/database");
m_ok = RLP(protocolContents).toInt<unsigned>(RLP::LaisezFaire) == c_protocolVersion && RLP(databaseContents).toInt<unsigned>(RLP::LaisezFaire) == c_databaseVersion;
}
void VersionChecker::setOk()

20
test/crypto.cpp

@ -46,12 +46,14 @@ BOOST_AUTO_TEST_CASE(crypto_tests)
t.nonce = 0;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
cnote << RLP(t.rlp(false));
cnote << toHex(t.rlp(false));
auto rlp = t.rlp(false);
cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(false);
t.sign(p.secret());
cnote << RLP(t.rlp(true));
cnote << toHex(t.rlp(true));
rlp = t.rlp(true);
cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(true);
BOOST_REQUIRE(t.sender() == p.address());
}
@ -72,12 +74,14 @@ int cryptoTest()
t.nonce = 0;
t.receiveAddress = h160(fromHex("944400f4b88ac9589a0f17ed4671da26bddb668b"));
t.value = 1000;
cnote << RLP(t.rlp(false));
cnote << toHex(t.rlp(false));
auto rlp = t.rlp(false);
cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(false);
t.sign(p.secret());
cnote << RLP(t.rlp(true));
cnote << toHex(t.rlp(true));
rlp = t.rlp(true);
cnote << RLP(rlp);
cnote << toHex(rlp);
cnote << t.sha3(true);
assert(t.sender() == p.address());
}

Loading…
Cancel
Save