From c8eaadb5d70f42723517bb028f363e37726be256 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 16 Oct 2019 22:53:34 +0200 Subject: 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(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 --- cppu/source/cppu/cppu_opt.cxx | 16 +++++----------- cppu/source/typelib/static_types.cxx | 6 +----- cppu/source/uno/lbenv.cxx | 8 +++----- 3 files changed, 9 insertions(+), 21 deletions(-) (limited to 'cppu/source') diff --git a/cppu/source/cppu/cppu_opt.cxx b/cppu/source/cppu/cppu_opt.cxx index 9ad9fbd98f0f..40f90de6e347 100644 --- a/cppu/source/cppu/cppu_opt.cxx +++ b/cppu/source/cppu/cppu_opt.cxx @@ -22,7 +22,7 @@ #include #include #include -#include +#include using namespace ::rtl; @@ -32,11 +32,8 @@ extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iquery_msg( typelib_TypeDescriptionReference * pType ) SAL_THROW_EXTERN_C() { - OUStringBuffer buf( 64 ); - buf.append( "unsatisfied query for interface of type " ); - buf.append( OUString::unacquired( &pType->pTypeName ) ); - buf.append( '!' ); - OUString ret( buf.makeStringAndClear() ); + OUString ret = "unsatisfied query for interface of type " + + OUString::unacquired( &pType->pTypeName ) + "!"; rtl_uString_acquire( ret.pData ); return ret.pData; } @@ -46,11 +43,8 @@ extern "C" rtl_uString * SAL_CALL cppu_unsatisfied_iset_msg( typelib_TypeDescriptionReference * pType ) SAL_THROW_EXTERN_C() { - OUStringBuffer buf( 64 ); - buf.append( "invalid attempt to assign an empty interface of type " ); - buf.append( OUString::unacquired( &pType->pTypeName ) ); - buf.append( '!' ); - OUString ret( buf.makeStringAndClear() ); + OUString ret = "invalid attempt to assign an empty interface of type " + + OUString::unacquired( &pType->pTypeName ) + "!"; rtl_uString_acquire( ret.pData ); return ret.pData; } diff --git a/cppu/source/typelib/static_types.cxx b/cppu/source/typelib/static_types.cxx index f88e642aeb7b..5a400817115d 100644 --- a/cppu/source/typelib/static_types.cxx +++ b/cppu/source/typelib/static_types.cxx @@ -24,7 +24,6 @@ #include #include -#include #include #include @@ -297,10 +296,7 @@ void SAL_CALL typelib_static_sequence_type_init( MutexGuard aGuard( typelib_StaticInitMutex::get() ); if (! *ppRef) { - OUStringBuffer aBuf( 32 ); - aBuf.append( "[]" ); - aBuf.append( pElementType->pTypeName ); - OUString aTypeName( aBuf.makeStringAndClear() ); + OUString aTypeName = "[]" + OUString::unacquired(&pElementType->pTypeName); assert( ! TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(typelib_TypeClass_SEQUENCE) ); *ppRef = igetTypeByName( aTypeName.pData ); diff --git a/cppu/source/uno/lbenv.cxx b/cppu/source/uno/lbenv.cxx index fd1464d5244f..10995e7ad3e0 100644 --- a/cppu/source/uno/lbenv.cxx +++ b/cppu/source/uno/lbenv.cxx @@ -774,11 +774,9 @@ extern "C" void SAL_CALL uno_dumpEnvironmentByName( } else { - OUStringBuffer buf( 32 ); - buf.append( "environment \"" ); - buf.append( pEnvDcp ); - buf.append( "\" does not exist!" ); - writeLine( stream, buf.makeStringAndClear(), pFilter ); + writeLine( + stream, "environment \"" + OUString::unacquired(&pEnvDcp) + "\" does not exist!", + pFilter ); } } -- cgit v1.2.3