From f03d646ffd39b3fca3197c16e1d579c78fdb9c4e Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Wed, 7 Oct 2020 14:05:53 -0400 Subject: [PATCH] CollectionBase: Fix cppcheck warnings. - Prefer pre-increment (or range-for) to postincrement. - Pass class instances by const reference, not by value. - Fix out-of-bounds reference. --- .../CollectionBase/CollectionColumn.h | 4 ++-- .../CollectionBase/CollectionDescription.h | 4 ++-- .../CollectionBase/CollectionFactory.h | 2 +- .../CollectionBase/CollectionFragment.h | 4 ++-- .../src/CollectionDescription.cpp | 18 +++++++++--------- .../CollectionBase/src/CollectionFactory.cpp | 2 +- Database/APR/CollectionBase/src/TokenList.cpp | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Database/APR/CollectionBase/CollectionBase/CollectionColumn.h b/Database/APR/CollectionBase/CollectionBase/CollectionColumn.h index c08e7502e9e..9ceb344ab09 100755 --- a/Database/APR/CollectionBase/CollectionBase/CollectionColumn.h +++ b/Database/APR/CollectionBase/CollectionBase/CollectionColumn.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef COLLECTIONBASE_COLLECTIONCOLUMN_H @@ -44,7 +44,7 @@ namespace pool { */ CollectionColumn( const std::string& name, const std::string& type, - std::string fragmentName = "", + const std::string& fragmentName = "", int maxSize = 0, bool sizeIsFixed = true ) : m_name( name ), diff --git a/Database/APR/CollectionBase/CollectionBase/CollectionDescription.h b/Database/APR/CollectionBase/CollectionBase/CollectionDescription.h index 47ad8118aa8..115a0a20b3c 100755 --- a/Database/APR/CollectionBase/CollectionBase/CollectionDescription.h +++ b/Database/APR/CollectionBase/CollectionBase/CollectionDescription.h @@ -47,8 +47,8 @@ namespace pool { */ CollectionDescription( const std::string& name, const std::string& type, - std::string connection = "", - std::string eventReferenceColumnName = "" ); + const std::string& connection = "", + const std::string& eventReferenceColumnName = "" ); /** * Copy constructor. diff --git a/Database/APR/CollectionBase/CollectionBase/CollectionFactory.h b/Database/APR/CollectionBase/CollectionBase/CollectionFactory.h index 3adbcc2f53d..325812ff9a7 100755 --- a/Database/APR/CollectionBase/CollectionBase/CollectionFactory.h +++ b/Database/APR/CollectionBase/CollectionBase/CollectionFactory.h @@ -211,7 +211,7 @@ namespace pool { * @param name Name of collection. * @param physicalName physical name of collection in catalog. */ - void extract( const std::string physicalName, + void extract( const std::string& physicalName, std::string& type, std::string& connection, std::string& name ) const; diff --git a/Database/APR/CollectionBase/CollectionBase/CollectionFragment.h b/Database/APR/CollectionBase/CollectionBase/CollectionFragment.h index c8e8de269d0..97d82867602 100755 --- a/Database/APR/CollectionBase/CollectionBase/CollectionFragment.h +++ b/Database/APR/CollectionBase/CollectionBase/CollectionFragment.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ #ifndef COLLECTIONBASE_COLLECTIONFRAGMENT_H @@ -38,7 +38,7 @@ namespace pool { * @param usesForeignKey Flag indicating whether fragment uses foreign key to reference parent fragment. */ CollectionFragment( const std::string& name, - std::string parentFragmentName = "", + const std::string& parentFragmentName = "", bool usesForeignKey = true ) : m_name( name ), m_parentFragmentName( parentFragmentName ), diff --git a/Database/APR/CollectionBase/src/CollectionDescription.cpp b/Database/APR/CollectionBase/src/CollectionDescription.cpp index b9e9902a8cf..846898560a2 100755 --- a/Database/APR/CollectionBase/src/CollectionDescription.cpp +++ b/Database/APR/CollectionBase/src/CollectionDescription.cpp @@ -20,8 +20,8 @@ using namespace std; pool::CollectionDescription::CollectionDescription( const std::string& name, const std::string& type, - std::string connection, - std::string eventReferenceColumnName ) + const std::string& connection, + const std::string& eventReferenceColumnName ) : m_name( name ), m_type( type ), m_connection( connection ), @@ -343,7 +343,7 @@ pool::CollectionDescription::setName( const std::string& name ) // rename frament in column map for( std::map< std::string, std::string >::iterator colI = m_fragmentNameForColumnName.begin(); colI != m_fragmentNameForColumnName.end(); - colI++ ) { + ++colI ) { if( colI->second == m_name ) { colI->second = name; // change the reference inside the column @@ -409,7 +409,7 @@ pool::CollectionDescription::setColumnId( pool::CollectionColumn *column, int id while( column_iter != m_columnIdForColumnName.end() ) { if( id < column_iter->second ) id = column_iter->second; - column_iter++; + ++column_iter; } id++; } @@ -869,8 +869,8 @@ pool::CollectionDescription::createIndex( std::string indexName, const std::vect // Generate unique name for index. if( !indexName.size() ) { indexName = fragmentName; - for( std::vector< std::string >::const_iterator iName = columnNames.begin(); iName != columnNames.end(); iName++ ) { - indexName += "_" + *iName; + for (const std::string& name : columnNames) { + indexName += "_" + name; } indexName += "_IDX"; } @@ -1023,9 +1023,9 @@ setUniqueConstraint( std::string constraintName, const std::vector< std::string if( !constraintName.size() ) { // Generate unique name for unique constraint. constraintName = fragmentName; - for ( std::vector< std::string >::const_iterator iName = columnNames.begin(); iName != columnNames.end(); iName++ ) + for (const std::string& name : columnNames) { - constraintName += "_" + *iName; + constraintName += "_" + name; } constraintName += "_UC"; } @@ -1109,7 +1109,7 @@ pool::CollectionDescription::unsetUniqueConstraint( const std::vector< std::stri delete *iConstraint; iConstraint = m_uniqueConstraints.erase( iConstraint ); for ( std::map< std::string, pool::CollectionColumn* >::iterator iColumn = columnForColumnName.begin(); - iColumn != columnForColumnName.end(); iColumn++ ) + iColumn != columnForColumnName.end(); ++iColumn ) { iColumn->second->setIsUnique( false ); } diff --git a/Database/APR/CollectionBase/src/CollectionFactory.cpp b/Database/APR/CollectionBase/src/CollectionFactory.cpp index 29de465160d..aaac3fb67a9 100755 --- a/Database/APR/CollectionBase/src/CollectionFactory.cpp +++ b/Database/APR/CollectionBase/src/CollectionFactory.cpp @@ -466,7 +466,7 @@ pool::CollectionFactory::isUnique( const pool::FileCatalog::FileID& guid, void -pool::CollectionFactory::extract( const std::string physicalName, +pool::CollectionFactory::extract( const std::string& physicalName, std::string& type, std::string& connection, std::string& name ) const diff --git a/Database/APR/CollectionBase/src/TokenList.cpp b/Database/APR/CollectionBase/src/TokenList.cpp index 17b8cf9a472..d999fb19b18 100755 --- a/Database/APR/CollectionBase/src/TokenList.cpp +++ b/Database/APR/CollectionBase/src/TokenList.cpp @@ -158,7 +158,7 @@ pool::TokenList::operator[]( unsigned int index ) const std::ostream& pool::TokenList::toOutputStream( std::ostream& os ) const { - for( size_t i = 0; i <= m_tokenVector.size(); ++i ) { + for( size_t i = 0; i < m_tokenVector.size(); ++i ) { os << "[" << m_tokenNames[i] << " (Token) : " << m_tokenVector[i]->toString()<< "]"; } -- GitLab