Fixing additional signedness errors after adding -Wsign-conversion flag

Co-authored-by: Kamil Śliwak <kamil.sliwak@codepoets.it>
This commit is contained in:
Djordje Mijovic 2020-06-15 12:51:58 +02:00
parent 3c57e04751
commit 547590b972
12 changed files with 20 additions and 20 deletions

View File

@ -245,14 +245,14 @@ unsigned SemVerMatchExpressionParser::parseVersionPart()
return 0;
else if ('1' <= c && c <= '9')
{
unsigned v(c - '0');
auto v = static_cast<unsigned>(c - '0');
// If we skip to the next token, the current number is terminated.
while (m_pos == startPos && '0' <= currentChar() && currentChar() <= '9')
{
c = currentChar();
if (v * 10 < v || v * 10 + unsigned(c - '0') < v * 10)
if (v * 10 < v || v * 10 + static_cast<unsigned>(c - '0') < v * 10)
throw SemVerError();
v = v * 10 + unsigned(c - '0');
v = v * 10 + static_cast<unsigned>(c - '0');
nextChar();
}
return v;

View File

@ -191,7 +191,7 @@ CVC4::Expr CVC4Interface::toCVC4Expr(Expression const& _expr)
return m_context.mkExpr(CVC4::kind::BITVECTOR_AND, arguments[0], arguments[1]);
else if (n == "int2bv")
{
size_t size = std::stoi(_expr.arguments[1].name);
size_t size = std::stoul(_expr.arguments[1].name);
auto i2bvOp = m_context.mkConst(CVC4::IntToBitVector(size));
// CVC4 treats all BVs as unsigned, so we need to manually apply 2's complement if needed.
return m_context.mkExpr(

View File

@ -139,7 +139,7 @@ string SMTLib2Interface::toSExpr(Expression const& _expr)
std::string sexpr = "(";
if (_expr.name == "int2bv")
{
size_t size = std::stoi(_expr.arguments[1].name);
size_t size = std::stoul(_expr.arguments[1].name);
auto arg = toSExpr(_expr.arguments.front());
auto int2bv = "(_ int2bv " + to_string(size) + ")";
// Some solvers treat all BVs as unsigned, so we need to manually apply 2's complement if needed.

View File

@ -184,7 +184,7 @@ z3::expr Z3Interface::toZ3Expr(Expression const& _expr)
return arguments[0] & arguments[1];
else if (n == "int2bv")
{
size_t size = std::stoi(_expr.arguments[1].name);
size_t size = std::stoul(_expr.arguments[1].name);
return z3::int2bv(size, arguments[0]);
}
else if (n == "bv2int")

View File

@ -646,7 +646,7 @@ bool ContractCompiler::visit(FunctionDefinition const& _function)
}
else
{
m_context << swapInstruction(stackLayout.size() - static_cast<size_t>(stackLayout.back()) - 1);
m_context << swapInstruction(stackLayout.size() - static_cast<unsigned>(stackLayout.back()) - 1u);
swap(stackLayout[static_cast<size_t>(stackLayout.back())], stackLayout.back());
}
for (size_t i = 0; i < stackLayout.size(); ++i)

View File

@ -1253,7 +1253,7 @@ pair<smtutil::Expression, smtutil::Expression> SMTEncoder::arithmeticOperation(
// - RHS is -1
// the result is then -(type.min), which wraps back to type.min
smtutil::Expression maxLeft = _left == smt::minValue(*intType);
smtutil::Expression minusOneRight = _right == -1;
smtutil::Expression minusOneRight = _right == numeric_limits<size_t >::max();
smtutil::Expression wrap = smtutil::Expression::ite(maxLeft && minusOneRight, smt::minValue(*intType), valueUnbounded);
return {wrap, valueUnbounded};
}

View File

@ -165,7 +165,7 @@ void CodeTransform::deleteVariable(Scope::Variable const& _var)
{
yulAssert(m_allowStackOpt, "");
yulAssert(m_context->variableStackHeights.count(&_var) > 0, "");
m_unusedStackSlots.insert(m_context->variableStackHeights[&_var]);
m_unusedStackSlots.insert(static_cast<int>(m_context->variableStackHeights[&_var]));
m_context->variableStackHeights.erase(&_var);
m_context->variableReferences.erase(&_var);
m_variablesScheduledForDeletion.erase(&_var);
@ -402,7 +402,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
yulAssert(m_scope->identifiers.count(_function.name), "");
Scope::Function& function = std::get<Scope::Function>(m_scope->identifiers.at(_function.name));
int height = m_evm15 ? 0 : 1;
size_t height = m_evm15 ? 0 : 1;
yulAssert(m_info.scopes.at(&_function.body), "");
Scope* varScope = m_info.scopes.at(m_info.virtualBlocks.at(&_function).get()).get();
yulAssert(varScope, "");
@ -420,7 +420,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
else
m_assembly.appendLabel(functionEntryID(_function.name, function));
m_assembly.setStackHeight(height);
m_assembly.setStackHeight(static_cast<int>(height));
for (auto const& v: _function.returnVariables)
{
@ -457,7 +457,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
StackTooDeepError error(_error);
if (error.functionName.empty())
error.functionName = _function.name;
stackError(std::move(error), height);
stackError(std::move(error), static_cast<int>(height));
}
m_assembly.appendLabel(m_context->functionExitPoints.top().label);
@ -502,7 +502,7 @@ void CodeTransform::operator()(FunctionDefinition const& _function)
}
else
{
m_assembly.appendInstruction(evmasm::swapInstruction(stackLayout.size() - static_cast<size_t>(stackLayout.back()) - 1));
m_assembly.appendInstruction(evmasm::swapInstruction(static_cast<unsigned>(stackLayout.size()) - static_cast<unsigned>(stackLayout.back()) - 1u));
swap(stackLayout[static_cast<size_t>(stackLayout.back())], stackLayout.back());
}
for (size_t i = 0; i < stackLayout.size(); ++i)

View File

@ -184,13 +184,13 @@ void ProtoConverter::visit(VarRef const& _x)
{
// Ensure that there is at least one variable declaration to reference in function scope.
yulAssert(m_currentFuncVars.size() > 0, "Proto fuzzer: No variables to reference.");
m_output << *m_currentFuncVars[_x.varnum() % m_currentFuncVars.size()];
m_output << *m_currentFuncVars[static_cast<size_t>(_x.varnum()) % m_currentFuncVars.size()];
}
else
{
// Ensure that there is at least one variable declaration to reference in nested scopes.
yulAssert(m_currentGlobalVars.size() > 0, "Proto fuzzer: No global variables to reference.");
m_output << *m_currentGlobalVars[_x.varnum() % m_currentGlobalVars.size()];
m_output << *m_currentGlobalVars[static_cast<size_t>(_x.varnum()) % m_currentGlobalVars.size()];
}
}

View File

@ -202,7 +202,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
// With libFuzzer binary run this to generate a YUL source file x.yul:
// PROTO_FUZZER_DUMP_PATH=x.yul ./a.out proto-input
ofstream of(dump_path);
of.write(sol_source.data(), sol_source.size());
of.write(sol_source.data(), static_cast<streamsize>(sol_source.size()));
}
if (char const* dump_path = getenv("SOL_DEBUG_FILE"))

View File

@ -43,7 +43,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
// With libFuzzer binary run this to generate a YUL source file x.yul:
// PROTO_FUZZER_DUMP_PATH=x.yul ./a.out proto-input
ofstream of(dump_path);
of.write(yul_source.data(), yul_source.size());
of.write(yul_source.data(), static_cast<streamsize>(yul_source.size()));
}
if (yul_source.size() > 1200)

View File

@ -64,7 +64,7 @@ DEFINE_PROTO_FUZZER(Program const& _input)
// With libFuzzer binary run this to generate a YUL source file x.yul:
// PROTO_FUZZER_DUMP_PATH=x.yul ./a.out proto-input
ofstream of(dump_path);
of.write(yul_source.data(), yul_source.size());
of.write(yul_source.data(), static_cast<streamsize>(yul_source.size()));
}
YulStringRepository::reset();

View File

@ -179,8 +179,8 @@ BOOST_AUTO_TEST_CASE(alternativeMutations_should_choose_between_mutations_with_g
for (size_t i = 0; i < 10; ++i)
{
Chromosome mutatedChromosome = mutation(chromosome);
cCount += (mutatedChromosome == Chromosome("c") ? 1 : 0);
fCount += (mutatedChromosome == Chromosome("f") ? 1 : 0);
cCount += (mutatedChromosome == Chromosome("c") ? 1u : 0u);
fCount += (mutatedChromosome == Chromosome("f") ? 1u : 0u);
}
// This particular seed results in 7 "c"s out of 10 which looks plausible given the 80% chance.