From 5f313ee52aafe2dd4594f46d7ba2b96cb68fdc84 Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Tue, 6 Apr 2021 16:31:58 +0200 Subject: [PATCH] ControlFlowAnalyzer: Use temporary reference for more readable code --- libsolidity/analysis/ControlFlowAnalyzer.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libsolidity/analysis/ControlFlowAnalyzer.cpp b/libsolidity/analysis/ControlFlowAnalyzer.cpp index bcf0a9f64..1d8bf92ba 100644 --- a/libsolidity/analysis/ControlFlowAnalyzer.cpp +++ b/libsolidity/analysis/ControlFlowAnalyzer.cpp @@ -134,18 +134,20 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod for (auto const* variableOccurrence: uninitializedAccessesOrdered) { + VariableDeclaration const& varDecl = variableOccurrence->declaration(); + SecondarySourceLocation ssl; if (variableOccurrence->occurrence()) - ssl.append("The variable was declared here.", variableOccurrence->declaration().location()); + ssl.append("The variable was declared here.", varDecl.location()); - bool isStorage = variableOccurrence->declaration().type()->dataStoredIn(DataLocation::Storage); - bool isCalldata = variableOccurrence->declaration().type()->dataStoredIn(DataLocation::CallData); + bool isStorage = varDecl.type()->dataStoredIn(DataLocation::Storage); + bool isCalldata = varDecl.type()->dataStoredIn(DataLocation::CallData); if (isStorage || isCalldata) m_errorReporter.typeError( 3464_error, variableOccurrence->occurrence() ? *variableOccurrence->occurrence() : - variableOccurrence->declaration().location(), + varDecl.location(), ssl, "This variable is of " + string(isStorage ? "storage" : "calldata") + @@ -153,10 +155,10 @@ void ControlFlowAnalyzer::checkUninitializedAccess(CFGNode const* _entry, CFGNod (variableOccurrence->kind() == VariableOccurrence::Kind::Return ? "returned" : "accessed") + " without prior assignment, which would lead to undefined behaviour." ); - else if (!_emptyBody && variableOccurrence->declaration().name().empty()) + else if (!_emptyBody && varDecl.name().empty()) m_errorReporter.warning( 6321_error, - variableOccurrence->declaration().location(), + varDecl.location(), "Unnamed return variable can remain unassigned. Add an explicit return with value to all non-reverting code paths or name the variable." ); }