diff --git a/test/tools/ossfuzz/SolidityGenerator.cpp b/test/tools/ossfuzz/SolidityGenerator.cpp index 56b5e4d9d..52c35513e 100644 --- a/test/tools/ossfuzz/SolidityGenerator.cpp +++ b/test/tools/ossfuzz/SolidityGenerator.cpp @@ -301,7 +301,6 @@ string BlockStmtGenerator::visit() { if (nestingTooDeep()) return "\n"; - incrementNestingDepth(); ostringstream block; block << indentation() + "{\n"; @@ -345,11 +344,21 @@ string FunctionGenerator::visit() if (!state->currentFunctionState()->outputs.empty()) function << " returns" << state->currentFunctionState()->params(FunctionState::Params::OUTPUT); - function << "\n" << generator()->visit(); - generator()->endVisit(); + ostringstream block; + // Since visitChildren() may not visit block stmt, we default to an empty + // block. + block << visitChildren(); + if (block.str().empty()) + block << indentation() << "{ }\n"; + function << "\n" << block.str(); return function.str(); } +void FunctionGenerator::endVisit() +{ + mutator->generator()->resetNestingDepth(); +} + pair ExpressionGenerator::randomLValueExpression() { LValueExpr exprType = static_cast( diff --git a/test/tools/ossfuzz/SolidityGenerator.h b/test/tools/ossfuzz/SolidityGenerator.h index 603764429..5fd4a6488 100644 --- a/test/tools/ossfuzz/SolidityGenerator.h +++ b/test/tools/ossfuzz/SolidityGenerator.h @@ -288,13 +288,13 @@ public: { return name(); } - std::string name() + std::string name() const { return contractName; } - bool operator==(ContractType const&) + bool operator==(ContractType const& _rhs) { - return true; + return _rhs.name() == this->name(); } std::string contractName; }; @@ -530,7 +530,8 @@ struct TestState } void addSource() { - updateSourcePath(newPath()); + std::string path = newPath(); + updateSourcePath(path); } /// Increments indentation level globally. void indent() @@ -806,6 +807,7 @@ public: {} std::string visit() override; std::string name() override { return "Function generator"; } + void endVisit() override; void setup() override; /// Sets @name m_freeFunction to @param _freeFunction. void scope(bool _freeFunction) @@ -849,12 +851,20 @@ public: {} void endVisit() override { - m_nestingDepth = 0; + decrementNestingDepth(); } void incrementNestingDepth() { ++m_nestingDepth; } + void decrementNestingDepth() + { + --m_nestingDepth; + } + void resetNestingDepth() + { + m_nestingDepth = 0; + } bool nestingTooDeep() { return m_nestingDepth > s_maxNestingDepth;