aboutsummaryrefslogtreecommitdiffstats
path: root/solc/CommandLineInterface.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-09-06 17:12:55 +0800
committerchriseth <c@ethdev.com>2016-09-06 17:12:55 +0800
commitf869f25b842f4c800621197f5c1c3521732da5c6 (patch)
tree654da0b98777bde5745f20dc2b80196ca1b65b6a /solc/CommandLineInterface.cpp
parenta787e705948255e1ff2e1b70c6d8c5160e892fa3 (diff)
downloaddexon-solidity-f869f25b842f4c800621197f5c1c3521732da5c6.tar.gz
dexon-solidity-f869f25b842f4c800621197f5c1c3521732da5c6.tar.zst
dexon-solidity-f869f25b842f4c800621197f5c1c3521732da5c6.zip
More comments about size constants.
Diffstat (limited to 'solc/CommandLineInterface.cpp')
-rw-r--r--solc/CommandLineInterface.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp
index 48e7578f..d87429b5 100644
--- a/solc/CommandLineInterface.cpp
+++ b/solc/CommandLineInterface.cpp
@@ -778,12 +778,17 @@ void CommandLineInterface::actOnInput()
bool CommandLineInterface::link()
{
+ // Map from how the libraries will be named inside the bytecode to their addresses.
map<string, h160> librariesReplacements;
+ size_t const placeholderSize = 40; // 20 bytes or 40 hex characters
for (auto const& library: m_libraries)
{
string const& name = library.first;
+ // Library placeholders are 40 hex digits (20 bytes) that start and end with '__'.
+ // This leaves 36 characters for the library name, while too short library names are
+ // padded on the right with '_' and too long names are truncated.
string replacement = "__";
- for (size_t i = 0; i < 36; ++i)
+ for (size_t i = 0; i < placeholderSize - 4; ++i)
replacement.push_back(i < name.size() ? name[i] : '_');
replacement += "__";
librariesReplacements[replacement] = library.second;
@@ -795,13 +800,13 @@ bool CommandLineInterface::link()
{
while (it != end && *it != '_') ++it;
if (it == end) break;
- if (end - it < 40)
+ if (end - it < placeholderSize)
{
cerr << "Error in binary object file " << src.first << " at position " << (end - src.second.begin()) << endl;
return false;
}
- string name(it, it + 40);
+ string name(it, it + placeholderSize);
if (librariesReplacements.count(name))
{
string hexStr(toHex(librariesReplacements.at(name).asBytes()));
@@ -809,7 +814,7 @@ bool CommandLineInterface::link()
}
else
cerr << "Reference \"" << name << "\" in file \"" << src.first << "\" still unresolved." << endl;
- it += 40;
+ it += placeholderSize;
}
}
return true;