Merge pull request #11416 from ethereum/fix-asan-stack-use-after-scope-in-test-file-parser-test

Fix asan stack-use-after-scope in TestFileParserTest
This commit is contained in:
Leonardo 2021-05-20 12:54:33 +02:00 committed by GitHub
commit 1239c0c332
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 7 deletions

View File

@ -726,7 +726,7 @@ char TestFileParser::Scanner::scanHexPart()
return static_cast<char>(value);
}
bool TestFileParser::isBuiltinFunction(std::string const& signature)
bool TestFileParser::isBuiltinFunction(std::string const& _signature)
{
return m_builtins.count(signature) > 0;
return m_builtins.count(_signature) > 0;
}

View File

@ -52,7 +52,10 @@ class TestFileParser
public:
/// Constructor that takes an input stream \param _stream to operate on
/// and creates the internal scanner.
explicit TestFileParser(std::istream& _stream, std::map<std::string, Builtin> const& _builtins): m_scanner(_stream), m_builtins(_builtins) {}
explicit TestFileParser(std::istream& _stream, std::map<std::string, Builtin> const& _builtins):
m_scanner(_stream),
m_builtins(_builtins)
{}
/// Parses function calls blockwise and returns a list of function calls found.
/// Throws an exception if a function call cannot be parsed because of its
@ -179,7 +182,7 @@ private:
/// Checks whether a builtin function with the given signature exist.
/// @returns true, if builtin found, false otherwise
bool isBuiltinFunction(std::string const& signature);
bool isBuiltinFunction(std::string const& _signature);
/// A scanner instance
Scanner m_scanner;

View File

@ -44,9 +44,10 @@ namespace
vector<FunctionCall> parse(string const& _source)
{
static std::map<std::string, Builtin> const builtins = {};
istringstream stream{_source, ios_base::out};
TestFileParser parser{stream, {}};
return parser.parseFunctionCalls(0);
return TestFileParser{stream, builtins}.parseFunctionCalls(0);
}
void testFunctionCall(
@ -99,7 +100,7 @@ BOOST_AUTO_TEST_CASE(smoke_test)
BOOST_REQUIRE_EQUAL(parse(source).size(), 0);
}
BOOST_AUTO_TEST_CASE(call_succees)
BOOST_AUTO_TEST_CASE(call_success)
{
char const* source = R"(
// success() ->