summaryrefslogtreecommitdiff
path: root/connectivity
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-10-16 22:53:34 +0200
committerStephan Bergmann <sbergman@redhat.com>2019-10-17 09:03:53 +0200
commitc8eaadb5d70f42723517bb028f363e37726be256 (patch)
tree6d91ba30db1dde2c0ad00f0bd453bed937d98660 /connectivity
parent7972ce0d6bc22a36d7fbaaa19bed11ec4cfe52d7 (diff)
Remaining loplugin:bufferadd
...that had been missing because the plugin didn't implement postRun, so it didn't report anything when run as part of the shared plugin. (But did report the expected warnings when run as a standalone plugin during CompilerTest_compilerplugins_clang.) Most fixes are straightforward. A noteworthy one is PreparedStatement::setBytes in connectivity/source/drivers/postgresql/pq_preparedstatement.cxx: The old preallocation of a 20 character OStringBuffer might have prevented buf.append( reinterpret_cast<char *>(escapedString), len -1 ); from potentially throwing std::bad_alloc, which would have caused escapedString to be leaked. Even though that 20-character preallocation was likely just random junk and not meant to address the potential leak, lets address it now. Change-Id: Ib506332d061684a22a74e5e39e591539fd2c4900 Reviewed-on: https://gerrit.libreoffice.org/80925 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'connectivity')
-rw-r--r--connectivity/source/drivers/postgresql/pq_connection.cxx7
-rw-r--r--connectivity/source/drivers/postgresql/pq_databasemetadata.cxx48
-rw-r--r--connectivity/source/drivers/postgresql/pq_preparedstatement.cxx38
-rw-r--r--connectivity/source/drivers/postgresql/pq_statement.cxx78
-rw-r--r--connectivity/source/drivers/postgresql/pq_tools.cxx6
-rw-r--r--connectivity/source/drivers/postgresql/pq_xtables.cxx4
-rw-r--r--connectivity/source/drivers/postgresql/pq_xviews.cxx9
7 files changed, 56 insertions, 134 deletions
diff --git a/connectivity/source/drivers/postgresql/pq_connection.cxx b/connectivity/source/drivers/postgresql/pq_connection.cxx
index 0b5ea84bc6fa..56670cef1aa5 100644
--- a/connectivity/source/drivers/postgresql/pq_connection.cxx
+++ b/connectivity/source/drivers/postgresql/pq_connection.cxx
@@ -50,7 +50,6 @@
#include "pq_xviews.hxx"
#include "pq_xusers.hxx"
-#include <rtl/ustrbuf.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/uuid.h>
#include <rtl/bootstrap.hxx>
@@ -576,11 +575,7 @@ void Connection::initialize( const Sequence< Any >& aArguments )
if (isLog(&m_settings, LogLevel::Info))
{
- OUStringBuffer buf( 128 );
- buf.append( "connection to '" );
- buf.append( url );
- buf.append( "' successfully opened" );
- log(&m_settings, LogLevel::Info, buf.makeStringAndClear());
+ log(&m_settings, LogLevel::Info, "connection to '" + url + "' successfully opened");
}
}
diff --git a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx
index 99d2f22b86b3..4002d2fc866a 100644
--- a/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx
+++ b/connectivity/source/drivers/postgresql/pq_databasemetadata.cxx
@@ -1119,12 +1119,9 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getTables(
if (isLog(m_pSettings, LogLevel::Info))
{
- OUStringBuffer buf( 128 );
- buf.append( "DatabaseMetaData::getTables got called with " );
- buf.append( schemaPattern );
- buf.append( "." );
- buf.append( tableNamePattern );
- log(m_pSettings, LogLevel::Info, buf.makeStringAndClear());
+ log(m_pSettings, LogLevel::Info,
+ ("DatabaseMetaData::getTables got called with " + schemaPattern + "."
+ + tableNamePattern));
}
// ignore catalog, as a single pq connection does not support multiple catalogs
@@ -1453,14 +1450,9 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getColumns(
if (isLog(m_pSettings, LogLevel::Info))
{
- OUStringBuffer buf( 128 );
- buf.append( "DatabaseMetaData::getColumns got called with " );
- buf.append( schemaPattern );
- buf.append( "." );
- buf.append( tableNamePattern );
- buf.append( "." );
- buf.append( columnNamePattern );
- log(m_pSettings, LogLevel::Info, buf.makeStringAndClear());
+ log(m_pSettings, LogLevel::Info,
+ ("DatabaseMetaData::getColumns got called with " + schemaPattern + "."
+ + tableNamePattern + "." + columnNamePattern));
}
// ignore catalog, as a single pq connection
@@ -1634,14 +1626,9 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getColumnPrivileges(
if (isLog(m_pSettings, LogLevel::Info))
{
- OUStringBuffer buf( 128 );
- buf.append( "DatabaseMetaData::getColumnPrivileges got called with " );
- buf.append( schema );
- buf.append( "." );
- buf.append( table );
- buf.append( "." );
- buf.append( columnNamePattern );
- log(m_pSettings, LogLevel::Info, buf.makeStringAndClear());
+ log(m_pSettings, LogLevel::Info,
+ ("DatabaseMetaData::getColumnPrivileges got called with " + schema + "." + table + "."
+ + columnNamePattern));
}
Reference< XParameters > parameters( m_getColumnPrivs_stmt, UNO_QUERY_THROW );
@@ -1663,12 +1650,9 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getTablePrivileges(
if (isLog(m_pSettings, LogLevel::Info))
{
- OUStringBuffer buf( 128 );
- buf.append( "DatabaseMetaData::getTablePrivileges got called with " );
- buf.append( schemaPattern );
- buf.append( "." );
- buf.append( tableNamePattern );
- log(m_pSettings, LogLevel::Info, buf.makeStringAndClear());
+ log(m_pSettings, LogLevel::Info,
+ ("DatabaseMetaData::getTablePrivileges got called with " + schemaPattern + "."
+ + tableNamePattern));
}
Reference< XParameters > parameters( m_getTablePrivs_stmt, UNO_QUERY_THROW );
@@ -1721,12 +1705,8 @@ css::uno::Reference< XResultSet > DatabaseMetaData::getPrimaryKeys(
if (isLog(m_pSettings, LogLevel::Info))
{
- OUStringBuffer buf( 128 );
- buf.append( "DatabaseMetaData::getPrimaryKeys got called with " );
- buf.append( schema );
- buf.append( "." );
- buf.append( table );
- log(m_pSettings, LogLevel::Info, buf.makeStringAndClear());
+ log(m_pSettings, LogLevel::Info,
+ "DatabaseMetaData::getPrimaryKeys got called with " + schema + "." + table);
}
Reference< XPreparedStatement > statement = m_origin->prepareStatement(
diff --git a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
index 74254ebffd14..d30d62d9032e 100644
--- a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
+++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
@@ -53,6 +53,7 @@
#include <com/sun/star/sdbc/ResultSetType.hpp>
#include <com/sun/star/sdbc/SQLException.hpp>
+#include <memory>
#include <string.h>
#include <connectivity/dbconversion.hxx>
@@ -430,11 +431,7 @@ void PreparedStatement::setInt( sal_Int32 parameterIndex, sal_Int32 x )
MutexGuard guard(m_xMutex->GetMutex() );
checkClosed();
checkColumnIndex( parameterIndex );
- OStringBuffer buf( 20 );
- buf.append( "'" );
- buf.append( x );
- buf.append( "'" );
- m_vars[parameterIndex-1] = buf.makeStringAndClear();
+ m_vars[parameterIndex-1] = "'" + OString::number(x) + "'";
}
void PreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x )
@@ -442,11 +439,7 @@ void PreparedStatement::setLong( sal_Int32 parameterIndex, sal_Int64 x )
MutexGuard guard(m_xMutex->GetMutex() );
checkClosed();
checkColumnIndex( parameterIndex );
- OStringBuffer buf( 20 );
- buf.append( "'" );
- buf.append( x );
- buf.append( "'" );
- m_vars[parameterIndex-1] = buf.makeStringAndClear();
+ m_vars[parameterIndex-1] = "'" + OString::number(x) + "'";
}
void PreparedStatement::setFloat( sal_Int32 parameterIndex, float x )
@@ -454,11 +447,7 @@ void PreparedStatement::setFloat( sal_Int32 parameterIndex, float x )
MutexGuard guard(m_xMutex->GetMutex() );
checkClosed();
checkColumnIndex( parameterIndex );
- OStringBuffer buf( 20 );
- buf.append( "'" );
- buf.append( x );
- buf.append( "'" );
- m_vars[parameterIndex-1] = buf.makeStringAndClear();
+ m_vars[parameterIndex-1] = "'" + OString::number(x) + "'";
}
void PreparedStatement::setDouble( sal_Int32 parameterIndex, double x )
@@ -466,11 +455,7 @@ void PreparedStatement::setDouble( sal_Int32 parameterIndex, double x )
MutexGuard guard(m_xMutex->GetMutex() );
checkClosed();
checkColumnIndex( parameterIndex );
- OStringBuffer buf( 20 );
- buf.append( "'" );
- buf.append( x );
- buf.append( "'" );
- m_vars[parameterIndex-1] = buf.makeStringAndClear();
+ m_vars[parameterIndex-1] = "'" + OString::number(x) + "'";
}
void PreparedStatement::setString( sal_Int32 parameterIndex, const OUString& x )
@@ -496,21 +481,18 @@ void PreparedStatement::setBytes(
MutexGuard guard(m_xMutex->GetMutex() );
checkClosed();
checkColumnIndex( parameterIndex );
- OStringBuffer buf( 20 );
- buf.append( "'" );
size_t len;
- unsigned char * escapedString =
- PQescapeBytea( reinterpret_cast<unsigned char const *>(x.getConstArray()), x.getLength(), &len);
+ struct Free { void operator ()(void * p) const { free(p); } };
+ std::unique_ptr<unsigned char, Free> escapedString(
+ PQescapeBytea( reinterpret_cast<unsigned char const *>(x.getConstArray()), x.getLength(), &len));
if( ! escapedString )
{
throw SQLException(
"pq_preparedstatement.setBytes: Error during converting bytesequence to an SQL conform string",
*this, OUString(), 1, Any() );
}
- buf.append( reinterpret_cast<char *>(escapedString), len -1 );
- free( escapedString );
- buf.append( "'" );
- m_vars[parameterIndex-1] = buf.makeStringAndClear();
+ m_vars[parameterIndex-1]
+ = "'" + rtl::OStringView(reinterpret_cast<char *>(escapedString.get()), len -1) + "'";
}
diff --git a/connectivity/source/drivers/postgresql/pq_statement.cxx b/connectivity/source/drivers/postgresql/pq_statement.cxx
index b8303c1a5ad0..ae17e3bb5c81 100644
--- a/connectivity/source/drivers/postgresql/pq_statement.cxx
+++ b/connectivity/source/drivers/postgresql/pq_statement.cxx
@@ -218,14 +218,9 @@ void Statement::close( )
void Statement::raiseSQLException(
const OUString & sql, const char * errorMsg )
{
- OUStringBuffer buf(128);
- buf.append( "pq_driver: ");
- buf.append(
- OUString( errorMsg, strlen(errorMsg), ConnectionSettings::encoding ) );
- buf.append( " (caused by statement '" );
- buf.append( sql );
- buf.append( "')" );
- OUString error = buf.makeStringAndClear();
+ OUString error = "pq_driver: "
+ + OUString( errorMsg, strlen(errorMsg), ConnectionSettings::encoding )
+ + " (caused by statement '" + sql + "')";
log(m_pSettings, LogLevel::Error, error);
throw SQLException( error, *this, OUString(), 1, Any() );
}
@@ -319,11 +314,10 @@ static std::vector< OUString > lookupKeys(
keySupplier.clear();
if (isLog(pSettings, LogLevel::Info))
{
- OStringBuffer buf( 128 );
- buf.append( "Can't offer updateable result set because table " );
- buf.append( OUStringToOString(name, ConnectionSettings::encoding) );
- buf.append( " is duplicated, add schema to resolve ambiguity" );
- log(pSettings, LogLevel::Info, buf.makeStringAndClear().getStr());
+ OString buf = "Can't offer updateable result set because table "
+ + OUStringToOString(name, ConnectionSettings::encoding)
+ + " is duplicated, add schema to resolve ambiguity";
+ log(pSettings, LogLevel::Info, buf.getStr());
}
break;
}
@@ -336,11 +330,9 @@ static std::vector< OUString > lookupKeys(
{
if (isLog(pSettings, LogLevel::Info))
{
- OStringBuffer buf( 128 );
- buf.append( "Can't offer updateable result set ( table " );
- buf.append( OUStringToOString(table, ConnectionSettings::encoding) );
- buf.append( " is unknown)" );
- log(pSettings, LogLevel::Info, buf.makeStringAndClear().getStr());
+ OString buf = "Can't offer updateable result set ( table "
+ + OUStringToOString(table, ConnectionSettings::encoding) + " is unknown)";
+ log(pSettings, LogLevel::Info, buf.getStr());
}
}
@@ -382,11 +374,10 @@ static std::vector< OUString > lookupKeys(
{
if (isLog(pSettings, LogLevel::Info))
{
- OStringBuffer buf( 128 );
- buf.append( "Can't offer updateable result set ( table " );
- buf.append( OUStringToOString(table, ConnectionSettings::encoding) );
- buf.append( " does not have a primary key)" );
- log(pSettings, LogLevel::Info, buf.makeStringAndClear().getStr());
+ OString buf = "Can't offer updateable result set ( table "
+ + OUStringToOString(table, ConnectionSettings::encoding)
+ + " does not have a primary key)";
+ log(pSettings, LogLevel::Info, buf.getStr());
}
}
}
@@ -496,12 +487,8 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data )
}
else if( ! table.getLength() )
{
- OStringBuffer buf( 128 );
- buf.append( "can't support updateable resultset, because a single table in the "
- "WHERE part of the statement could not be identified (" );
- buf.append( cmd );
- buf.append( "." );
- aReason = buf.makeStringAndClear();
+ aReason = "can't support updateable resultset, because a single table in the "
+ "WHERE part of the statement could not be identified (" + cmd + ".";
}
else if( !sourceTableKeys.empty() )
{
@@ -518,22 +505,17 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data )
else
{
- OStringBuffer buf( 128 );
- buf.append( "can't support updateable resultset for table " );
- buf.append( OUStringToOString( schema, ConnectionSettings::encoding ) );
- buf.append( "." );
- buf.append( OUStringToOString( table, ConnectionSettings::encoding ) );
- buf.append( ", because resultset table does not have a primary key " );
- aReason = buf.makeStringAndClear();
+ aReason = "can't support updateable resultset for table "
+ + OUStringToOString( schema, ConnectionSettings::encoding ) + "."
+ + OUStringToOString( table, ConnectionSettings::encoding )
+ + ", because resultset table does not have a primary key ";
}
}
else
{
- OStringBuffer buf( 128 );
- buf.append( "can't support updateable result for selects with multiple tables (" );
- buf.append( cmd );
- buf.append( ")" );
- log(pSettings, LogLevel::Sql, buf.makeStringAndClear().getStr() );
+ OString buf = "can't support updateable result for selects with multiple tables ("
+ + cmd + ")";
+ log(pSettings, LogLevel::Sql, buf.getStr() );
}
if( ! (*(data->pLastResultset)).is() )
{
@@ -568,16 +550,10 @@ bool executePostgresCommand( const OString & cmd, struct CommandData *data )
ret = true;
if (isLog(pSettings, LogLevel::Sql))
{
- OStringBuffer buf( 128 );
- buf.append( "executed query '" );
- buf.append( cmd );
- buf.append( "' successfully" );
- buf.append( ", duration=" );
- buf.append( duration );
- buf.append( "ms, returnedRows=" );
- buf.append( returnedRows );
- buf.append( "." );
- log(pSettings, LogLevel::Sql, buf.makeStringAndClear().getStr());
+ OString buf = "executed query '" + cmd + "' successfully, duration="
+ + OString::number(duration) + "ms, returnedRows=" + OString::number(returnedRows)
+ + ".";
+ log(pSettings, LogLevel::Sql, buf.getStr());
}
break;
}
diff --git a/connectivity/source/drivers/postgresql/pq_tools.cxx b/connectivity/source/drivers/postgresql/pq_tools.cxx
index 63ed515e2659..20fa3b4bb215 100644
--- a/connectivity/source/drivers/postgresql/pq_tools.cxx
+++ b/connectivity/source/drivers/postgresql/pq_tools.cxx
@@ -88,11 +88,7 @@ namespace pq_sdbc_driver
OUString concatQualified( const OUString & a, const OUString &b)
{
- OUStringBuffer buf( a.getLength() + 2 + b.getLength() );
- buf.append( a );
- buf.append( "." );
- buf.append( b );
- return buf.makeStringAndClear();
+ return a + "." + b;
}
static OString iOUStringToOString( const OUString& str, ConnectionSettings const *settings) {
diff --git a/connectivity/source/drivers/postgresql/pq_xtables.cxx b/connectivity/source/drivers/postgresql/pq_xtables.cxx
index 2c57e8f10551..e15dc478e210 100644
--- a/connectivity/source/drivers/postgresql/pq_xtables.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xtables.cxx
@@ -133,9 +133,7 @@ void Tables::refresh()
{
m_values.push_back( makeAny( prop ) );
- OUStringBuffer buf( name.getLength() + schema.getLength() + 1);
- buf.append( schema ).append( "." ).append( name );
- map[ buf.makeStringAndClear() ] = tableIndex;
+ map[ schema + "." + name ] = tableIndex;
++tableIndex;
}
}
diff --git a/connectivity/source/drivers/postgresql/pq_xviews.cxx b/connectivity/source/drivers/postgresql/pq_xviews.cxx
index 2d0ed008fa4b..ac684a16c124 100644
--- a/connectivity/source/drivers/postgresql/pq_xviews.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xviews.cxx
@@ -115,9 +115,7 @@ void Views::refresh()
{
m_values.push_back( makeAny( prop ) );
- OUStringBuffer buf( table.getLength() + schema.getLength() + 1);
- buf.append( schema ).append( "." ).append( table );
- map[ buf.makeStringAndClear() ] = viewIndex;
+ map[ schema + "." + table ] = viewIndex;
++viewIndex;
}
}
@@ -191,12 +189,9 @@ void Views::dropByIndex( sal_Int32 index )
set->getPropertyValue( st.SCHEMA_NAME ) >>= schema;
set->getPropertyValue( st.NAME ) >>= name;
- OUStringBuffer update( 128 );
- update.append( "DROP VIEW \"" ).append( schema ).append( "\".\"" ).append( name ).append( "\"" );
-
Reference< XStatement > stmt = m_origin->createStatement( );
- stmt->executeUpdate( update.makeStringAndClear() );
+ stmt->executeUpdate( "DROP VIEW \"" + schema + "\".\"" + name + "\"" );
}