cppcheck: uselessCallsRemove
std::remove returns a past the end iterator which should be used
for the reallocation.
This makes the code more robust. Previously it only worked if
there was exactly one value with type XGeneratedResultSet in the
Sequence.
Change-Id: Ia2db1252ba8fe682dbc55d9722eaa62ed596e297
Reviewed-on: https://gerrit.libreoffice.org/39724
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/connectivity/source/drivers/jdbc/JStatement.cxx b/connectivity/source/drivers/jdbc/JStatement.cxx
index c89e3c4..fed0c3d 100644
--- a/connectivity/source/drivers/jdbc/JStatement.cxx
+++ b/connectivity/source/drivers/jdbc/JStatement.cxx
@@ -133,9 +133,9 @@ Sequence< Type > SAL_CALL java_sql_Statement_Base::getTypes( )
Sequence< Type > aOldTypes = java_sql_Statement_BASE::getTypes();
if ( m_pConnection.is() && !m_pConnection->isAutoRetrievingEnabled() )
{
std::remove(aOldTypes.begin(), aOldTypes.end(),
cppu::UnoType<XGeneratedResultSet>::get());
aOldTypes.realloc(aOldTypes.getLength() - 1);
auto newEnd = std::remove(aOldTypes.begin(), aOldTypes.end(),
cppu::UnoType<XGeneratedResultSet>::get());
aOldTypes.realloc(std::distance(aOldTypes.begin(), newEnd));
}
return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes);
diff --git a/connectivity/source/drivers/odbc/OStatement.cxx b/connectivity/source/drivers/odbc/OStatement.cxx
index 62ea765..6a038b6 100644
--- a/connectivity/source/drivers/odbc/OStatement.cxx
+++ b/connectivity/source/drivers/odbc/OStatement.cxx
@@ -139,9 +139,9 @@ Sequence< Type > SAL_CALL OStatement_Base::getTypes( )
Sequence< Type > aOldTypes = OStatement_BASE::getTypes();
if ( m_pConnection.is() && !m_pConnection->isAutoRetrievingEnabled() )
{
std::remove(aOldTypes.begin(), aOldTypes.end(),
cppu::UnoType<XGeneratedResultSet>::get());
aOldTypes.realloc(aOldTypes.getLength() - 1);
auto newEnd = std::remove(aOldTypes.begin(), aOldTypes.end(),
cppu::UnoType<XGeneratedResultSet>::get());
aOldTypes.realloc(std::distance(aOldTypes.begin(), newEnd));
}
return ::comphelper::concatSequences(aTypes.getTypes(),aOldTypes);