mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #6770 from ethereum/isoltest-parser-fix
[isoltest] TestFileParser: Fixes access of iterator at and beyond iterator ends
This commit is contained in:
commit
7183940e24
@ -72,6 +72,16 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
char TestFileParser::Scanner::peek() const noexcept
|
||||
{
|
||||
if (std::distance(m_char, m_line.end()) < 2)
|
||||
return '\0';
|
||||
|
||||
auto next = m_char;
|
||||
std::advance(next, 1);
|
||||
return *next;
|
||||
}
|
||||
|
||||
vector<dev::solidity::test::FunctionCall> TestFileParser::parseFunctionCalls()
|
||||
{
|
||||
vector<FunctionCall> calls;
|
||||
@ -561,7 +571,7 @@ void TestFileParser::Scanner::scanNextToken()
|
||||
else if (isWhiteSpace(current()))
|
||||
token = selectToken(Token::Whitespace);
|
||||
else if (isEndOfLine())
|
||||
token = selectToken(Token::EOS);
|
||||
token = make_pair(Token::EOS, "EOS");
|
||||
else
|
||||
throw Error(
|
||||
Error::Type::ParserError,
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <liblangutil/Exceptions.h>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@ -310,16 +311,30 @@ private:
|
||||
using TokenDesc = std::pair<Token, std::string>;
|
||||
|
||||
/// Advances current position in the input stream.
|
||||
void advance() { ++m_char; }
|
||||
/// Returns the current character.
|
||||
char current() const { return *m_char; }
|
||||
/// Peeks the next character.
|
||||
char peek() const { auto it = m_char; return *(it + 1); }
|
||||
void advance()
|
||||
{
|
||||
solAssert(m_char != m_line.end(), "Cannot advance beyond end.");
|
||||
++m_char;
|
||||
}
|
||||
|
||||
/// Returns the current character or '\0' if at end of input.
|
||||
char current() const noexcept
|
||||
{
|
||||
if (m_char == m_line.end())
|
||||
return '\0';
|
||||
|
||||
return *m_char;
|
||||
}
|
||||
|
||||
/// Retrieves the next character ('\0' if that would be at (or beyond) the end of input)
|
||||
/// without advancing the input stream iterator.
|
||||
char peek() const noexcept;
|
||||
|
||||
/// Returns true if the end of a line is reached, false otherwise.
|
||||
bool isEndOfLine() const { return m_char == m_line.end(); }
|
||||
|
||||
std::string m_line;
|
||||
std::string::iterator m_char;
|
||||
std::string::const_iterator m_char;
|
||||
|
||||
std::string m_currentLiteral;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user