From bd1989bd0bba90f8e14648e06c1c0e66b176b9b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Sat, 14 Nov 2020 00:20:52 +0100 Subject: [PATCH 1/3] CommandLineInterface::link(): Rename confusingly named "name" to "foundPlaceholder" --- solc/CommandLineInterface.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 64ef533a5..47af37d46 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -1786,14 +1786,14 @@ bool CommandLineInterface::link() return false; } - string name(it, it + placeholderSize); - if (librariesReplacements.count(name)) + string foundPlaceholder(it, it + placeholderSize); + if (librariesReplacements.count(foundPlaceholder)) { - string hexStr(toHex(librariesReplacements.at(name).asBytes())); + string hexStr(toHex(librariesReplacements.at(foundPlaceholder).asBytes())); copy(hexStr.begin(), hexStr.end(), it); } else - serr() << "Reference \"" << name << "\" in file \"" << src.first << "\" still unresolved." << endl; + serr() << "Reference \"" << foundPlaceholder << "\" in file \"" << src.first << "\" still unresolved." << endl; it += placeholderSize; } // Remove hints for resolved libraries. From f099d48b341e4e3be91aa40a2cc5db1ca9d9e858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Sat, 14 Nov 2020 00:24:08 +0100 Subject: [PATCH 2/3] CommandLineInterface::link(): Report an error if a placeholder does not have exactly four underscores --- solc/CommandLineInterface.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 47af37d46..7d3f7d763 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -1780,9 +1780,14 @@ bool CommandLineInterface::link() { while (it != end && *it != '_') ++it; if (it == end) break; - if (end - it < placeholderSize) + if ( + end - it < placeholderSize || + *(it + 1) != '_' || + *(it + placeholderSize - 2) != '_' || + *(it + placeholderSize - 1) != '_' + ) { - serr() << "Error in binary object file " << src.first << " at position " << (end - src.second.begin()) << endl; + serr() << "Error in binary object file " << src.first << " at position " << (it - src.second.begin()) << endl; return false; } From 2a8cff626b9be044a165475b70eef379f5bc7535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 19 Nov 2020 19:57:35 +0100 Subject: [PATCH 3/3] CommandLineInterface::link(): Print invalid link references to stderr --- solc/CommandLineInterface.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/solc/CommandLineInterface.cpp b/solc/CommandLineInterface.cpp index 7d3f7d763..b74cc224f 100644 --- a/solc/CommandLineInterface.cpp +++ b/solc/CommandLineInterface.cpp @@ -55,6 +55,7 @@ #include #include +#include #include #include @@ -1788,6 +1789,7 @@ bool CommandLineInterface::link() ) { serr() << "Error in binary object file " << src.first << " at position " << (it - src.second.begin()) << endl; + serr() << '"' << string(it, it + min(placeholderSize, static_cast(end - it))) << "\" is not a valid link reference." << endl; return false; }