Merge pull request #12740 from ethereum/remove-locale-dependent-operations

Replace all locale-dependent operations with locale-agnostic counterparts
This commit is contained in:
chriseth
2022-03-07 17:56:58 +01:00
committed by GitHub
16 changed files with 106 additions and 52 deletions
+7 -6
View File
@@ -29,7 +29,6 @@
using namespace std;
using namespace solidity;
using namespace solidity::util;
using namespace solidity::util::formatting;
using namespace solidity::langutil;
using namespace solidity::frontend;
@@ -43,10 +42,11 @@ namespace
int parseUnsignedInteger(string::iterator& _it, string::iterator _end)
{
if (_it == _end || !isdigit(*_it))
auto isDigit = [](char _c) -> bool {return isdigit(_c, std::locale::classic());};
if (_it == _end || !isDigit(*_it))
BOOST_THROW_EXCEPTION(runtime_error("Invalid test expectation. Source location expected."));
int result = 0;
while (_it != _end && isdigit(*_it))
while (_it != _end && isDigit(*_it))
{
result *= 10;
result += *_it - '0';
@@ -195,6 +195,7 @@ string CommonSyntaxTest::errorMessage(Exception const& _e)
vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
{
auto isDigit = [](char _c) -> bool {return isdigit(_c, std::locale::classic());};
vector<SyntaxTestError> expectations;
string line;
while (getline(_stream, line))
@@ -207,14 +208,14 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
if (it == line.end()) continue;
auto typeBegin = it;
while (it != line.end() && isalpha(*it))
while (it != line.end() && isalpha(*it, locale::classic()))
++it;
string errorType(typeBegin, it);
skipWhitespace(it, line.end());
optional<ErrorId> errorId;
if (it != line.end() && isdigit(*it))
if (it != line.end() && isDigit(*it))
errorId = ErrorId{static_cast<unsigned long long>(parseUnsignedInteger(it, line.end()))};
expect(it, line.end(), ':');
@@ -227,7 +228,7 @@ vector<SyntaxTestError> CommonSyntaxTest::parseExpectations(istream& _stream)
if (it != line.end() && *it == '(')
{
++it;
if (it != line.end() && !isdigit(*it))
if (it != line.end() && !isDigit(*it))
{
auto sourceNameStart = it;
while (it != line.end() && *it != ':')
+1 -1
View File
@@ -118,7 +118,7 @@ EVMVersionRestrictedTestCase::EVMVersionRestrictedTestCase(string const& _filena
string comparator;
size_t versionBegin = 0;
for (auto character: versionString)
if (!isalpha(character))
if (!isalpha(character, locale::classic()))
{
comparator += character;
versionBegin++;
+1 -1
View File
@@ -90,7 +90,7 @@ protected:
template<typename IteratorType>
static void skipWhitespace(IteratorType& _it, IteratorType _end)
{
while (_it != _end && isspace(*_it))
while (_it != _end && std::isspace<char>(*_it, std::locale::classic()))
++_it;
}
+2 -1
View File
@@ -22,6 +22,7 @@
#include <libsolutil/CommonData.h>
#include <libsolutil/CommonIO.h>
#include <libsolutil/StringUtils.h>
#include <boost/algorithm/string.hpp>
@@ -216,7 +217,7 @@ string BytesUtils::formatString(bytes const& _bytes, size_t _cutOff)
os << "\\n";
break;
default:
if (isprint(v))
if (isPrint(static_cast<char>(v)))
os << v;
else
os << "\\x" << toHex(v, HexCase::Lower);
+9 -6
View File
@@ -762,13 +762,16 @@ string TestFileParser::Scanner::scanString()
// TODO: use fromHex() from CommonData
char TestFileParser::Scanner::scanHexPart()
{
auto toLower = [](char _c) -> char { return tolower(_c, locale::classic()); };
auto isDigit = [](char _c) -> bool { return isdigit(_c, locale::classic()); };
advance(); // skip 'x'
int value{};
if (isdigit(current()))
if (isDigit(current()))
value = current() - '0';
else if (tolower(current()) >= 'a' && tolower(current()) <= 'f')
value = tolower(current()) - 'a' + 10;
else if (toLower(current()) >= 'a' && toLower(current()) <= 'f')
value = toLower(current()) - 'a' + 10;
else
BOOST_THROW_EXCEPTION(TestParserError("\\x used with no following hex digits."));
@@ -777,10 +780,10 @@ char TestFileParser::Scanner::scanHexPart()
return static_cast<char>(value);
value <<= 4;
if (isdigit(current()))
if (isDigit(current()))
value |= current() - '0';
else if (tolower(current()) >= 'a' && tolower(current()) <= 'f')
value |= tolower(current()) - 'a' + 10;
else if (toLower(current()) >= 'a' && toLower(current()) <= 'f')
value |= toLower(current()) - 'a' + 10;
advance();
@@ -28,6 +28,7 @@
#include <libsolutil/CommonIO.h>
#include <libsolutil/CommonData.h>
#include <libsolutil/StringUtils.h>
#include <test/tools/ossfuzz/yulFuzzerCommon.h>
@@ -53,7 +54,7 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* _data, size_t _size)
string input(reinterpret_cast<char const*>(_data), _size);
if (std::any_of(input.begin(), input.end(), [](char c) {
return ((static_cast<unsigned char>(c) > 127) || !(std::isprint(c) || (c == '\n') || (c == '\t')));
return ((static_cast<unsigned char>(c) > 127) || !(isPrint(c) || (c == '\n') || (c == '\t')));
}))
return 0;
+2 -1
View File
@@ -21,6 +21,7 @@
#include <libsolutil/CommonIO.h>
#include <libsolutil/Exceptions.h>
#include <libsolutil/StringUtils.h>
#include <liblangutil/ErrorReporter.h>
#include <libyul/AsmAnalysis.h>
#include <libyul/AsmAnalysisInfo.h>
@@ -155,7 +156,7 @@ public:
return (
!boost::algorithm::iequals(get<1>(_a), get<1>(_b)) ?
boost::algorithm::lexicographical_compare(get<1>(_a), get<1>(_b), boost::algorithm::is_iless()) :
tolower(get<0>(_a)) < tolower(get<0>(_b))
toLower(get<0>(_a)) < toLower(get<0>(_b))
);
});