diff options
author | Jochen Nitschke <j.nitschke+logerrit@ok.de> | 2017-07-08 15:38:39 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-09 15:42:19 +0200 |
commit | b91cb7d137b5d8fd203bbdc1c4e3d0e851fd5aa6 (patch) | |
tree | e92584b43e762193fe0e7371f103dd66724cc919 | |
parent | add test for non-ascii gnumeric file names, tdf#107827 (diff) | |
download | core-b91cb7d137b5d8fd203bbdc1c4e3d0e851fd5aa6.tar.gz core-b91cb7d137b5d8fd203bbdc1c4e3d0e851fd5aa6.zip |
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>
-rw-r--r-- | connectivity/source/drivers/jdbc/JStatement.cxx | 6 | ||||
-rw-r--r-- | connectivity/source/drivers/odbc/OStatement.cxx | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/connectivity/source/drivers/jdbc/JStatement.cxx b/connectivity/source/drivers/jdbc/JStatement.cxx index c89e3c4e6f51..fed0c3d7be15 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 62ea7650590c..6a038b66c1a9 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); |