From 2db7fe145b832c9762c67de90534af09d05e93dd Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Sat, 2 Nov 2019 22:44:17 +0100
Subject: [PATCH] fix some cppcheck issues

---
 alib2abstraction/src/registry/CastRegistry.cpp      | 2 +-
 alib2algo/src/automaton/run/Run.h                   | 6 ------
 alib2algo/src/string/naive/ExactCompare.h           | 3 +--
 alib2algo/src/string/naive/ExactEqual.h             | 3 +--
 alib2algo_experimental/src/grammar/parsing/Follow.h | 2 +-
 5 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/alib2abstraction/src/registry/CastRegistry.cpp b/alib2abstraction/src/registry/CastRegistry.cpp
index 089f7e3b59..bf27b873de 100644
--- a/alib2abstraction/src/registry/CastRegistry.cpp
+++ b/alib2abstraction/src/registry/CastRegistry.cpp
@@ -51,7 +51,7 @@ bool CastRegistry::isNoOp ( const std::string & target, const std::string & para
 bool CastRegistry::castAvailable ( const std::string & target, const std::string & param, bool implicitOnly ) {
 	for ( const std::pair < const ext::pair < std::string, std::string >, std::unique_ptr < Entry > > & entry : getEntries ( ) )
 		if (	   ( entry.first.second == param && ext::is_same_type ( target, ext::erase_template_info ( entry.first.first ) ) )
-				&& ( ! implicitOnly || ( implicitOnly && ! entry.second->isExplicit ( ) ) ) )
+				&& ( ! implicitOnly || ! entry.second->isExplicit ( ) ) )
 			return true;
 
 	return false;
diff --git a/alib2algo/src/automaton/run/Run.h b/alib2algo/src/automaton/run/Run.h
index 4cc35caa49..4c6a05225a 100644
--- a/alib2algo/src/automaton/run/Run.h
+++ b/alib2algo/src/automaton/run/Run.h
@@ -816,17 +816,11 @@ struct graphStructuredStack {
 template < class InputSymbolType, class OutputSymbolType, class PushdownStoreSymbolType, class StateType >
 ext::tuple < bool, ext::set < StateType >, ext::set < ext::vector < OutputSymbolType > > > Run::calculateStates ( const automaton::NPDTA < InputSymbolType, OutputSymbolType, PushdownStoreSymbolType, StateType > & automaton, const string::LinearString < InputSymbolType > & string ) {
 	bool res = false;
-	unsigned i = 0;
-	ext::set < unsigned > occurrences;
 	StateType state = automaton . getInitialState ();
 	typename ext::vector<InputSymbolType>::const_iterator symbolIter = string . getContent () . begin ();
 	std::shared_ptr < graphStructuredStack < InputSymbolType > > stackNode = std::make_shared < graphStructuredStack < InputSymbolType > > ( nullptr, * symbolIter );
 	std::shared_ptr < graphStructuredStack < InputSymbolType > > outputNode = std::make_shared < graphStructuredStack < InputSymbolType > > ( nullptr, * symbolIter );
 
-	if ( automaton . getFinalStates () . count ( state ) ) {
-		occurrences . insert ( i );
-	}
-
 	ext::deque < ext::tuple < StateType, typename ext::vector<InputSymbolType>::const_iterator, std::shared_ptr < graphStructuredStack < InputSymbolType > >, std::shared_ptr < graphStructuredStack < InputSymbolType > > > > bftQueue;
 	auto configuration = ext::make_tuple ( state, symbolIter, stackNode, outputNode );
 	bftQueue . push_back ( configuration );
diff --git a/alib2algo/src/string/naive/ExactCompare.h b/alib2algo/src/string/naive/ExactCompare.h
index 14984522af..2359b81218 100644
--- a/alib2algo/src/string/naive/ExactCompare.h
+++ b/alib2algo/src/string/naive/ExactCompare.h
@@ -74,12 +74,11 @@ int ExactCompare::compare ( const string::CyclicString < SymbolType > & u, const
 	int m = ( int ) v.getContent ( ).size ( );
 	int i = -1;
 	int j = -1;
-	int k;
 
 	bool last = false;
 
 	while ( i < n - 1 && j < m - 1 ) {
-		k = 1;
+		int k = 1;
 
 		while ( k <= n && u.getContent ( )[( i + k ) % n] == v.getContent ( )[( j + k ) % m] ) k++;
 
diff --git a/alib2algo/src/string/naive/ExactEqual.h b/alib2algo/src/string/naive/ExactEqual.h
index 8c8091e039..b885af6481 100644
--- a/alib2algo/src/string/naive/ExactEqual.h
+++ b/alib2algo/src/string/naive/ExactEqual.h
@@ -67,12 +67,11 @@ bool ExactEqual::equals ( const string::CyclicString < SymbolType > & u, const s
 	int n = ( int ) u.getContent ( ).size ( );
 	int i = -1;
 	int j = -1;
-	int k;
 
 	if ( n != ( int ) v.getContent ( ).size ( ) ) return false;
 
 	while ( i < n - 1 && j < n - 1 ) {
-		k = 1;
+		int k = 1;
 
 		while ( k <= n && u.getContent ( )[( i + k ) % n] == v.getContent ( )[( j + k ) % n] ) k++;
 
diff --git a/alib2algo_experimental/src/grammar/parsing/Follow.h b/alib2algo_experimental/src/grammar/parsing/Follow.h
index d9c14621ea..67fd5637e0 100644
--- a/alib2algo_experimental/src/grammar/parsing/Follow.h
+++ b/alib2algo_experimental/src/grammar/parsing/Follow.h
@@ -44,7 +44,7 @@ void Follow::follow ( const T & grammar, ext::map < NonterminalSymbolType, ext::
 
 		for ( const ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > > & rhs : rule.second )
 			 // every nt in rhs is Y
-			for ( typename ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >::const_iterator it = rhs.begin ( ); it != rhs.end ( ); it++ ) {
+			for ( typename ext::vector < ext::variant < TerminalSymbolType, NonterminalSymbolType > >::const_iterator it = rhs.begin ( ); it != rhs.end ( ); ++ it ) {
 				const ext::variant < TerminalSymbolType, NonterminalSymbolType > & Y = * it;
 
 				if ( ! grammar.getNonterminalAlphabet ( ).count ( Y ) )
-- 
GitLab