diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-11-10 17:46:57 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-11-11 00:03:37 +0100 |
commit | 1fc79c3491906d85ed9972e161112459035b62ed (patch) | |
tree | 29f284f4a814b2b7a61417046364b489ce2187d7 /include/rtl | |
parent | f697d06b67e91c704c088dceafade209462e0b95 (diff) |
Avoid using O[U]StringConcat lvalues containing dangling refs to temporaries
...in code accidentally using auto like
> auto const aURL = uri->getUriReference() + "/"
> + INetURLObject::encode(
> m_sEmbeddedName, INetURLObject::PART_FPATH,
> INetURLObject::EncodeMechanism::All);
>
> uno::Reference<uno::XInterface> xDataSource(xDatabaseContext->getByName(aURL), uno::UNO_QUERY);
in <https://gerrit.libreoffice.org/#/c/44569/1> "Properly construct
vnd.sun.star.pkg URL" did (causing hard to debug test failures there).
So make functions taking O[U]StringConcat take those by rvalue reference.
Unfortunately, that also needed adaption of various functions that just forward
their arguments. And some code in sc/qa/unit/ucalc_formula.cxx used
CPPUNIT_ASSERT_EQUAL on OUStringConcat arguments in cases where that happened to
actually compile (because the structure of the two OUStringConcats was
identical), which needed adaption too (but which would arguably better use
CPPUNIT_ASSERT_EQUAL_MESSAGE, anyway).
Change-Id: I8994d932aaedb2a491c7c81c167e93379d4fb6e3
Reviewed-on: https://gerrit.libreoffice.org/44608
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/rtl')
-rw-r--r-- | include/rtl/strbuf.hxx | 6 | ||||
-rw-r--r-- | include/rtl/string.hxx | 11 | ||||
-rw-r--r-- | include/rtl/ustrbuf.hxx | 6 | ||||
-rw-r--r-- | include/rtl/ustring.hxx | 11 |
4 files changed, 18 insertions, 16 deletions
diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx index 638c30bb957a..0c3b53d8e8b4 100644 --- a/include/rtl/strbuf.hxx +++ b/include/rtl/strbuf.hxx @@ -214,7 +214,7 @@ public: @internal */ template< typename T1, typename T2 > - OStringBuffer( const OStringConcat< T1, T2 >& c ) + OStringBuffer( OStringConcat< T1, T2 >&& c ) { const sal_Int32 l = c.length(); nCapacity = l + 16; @@ -279,7 +279,7 @@ public: #if defined LIBO_INTERNAL_ONLY /** @overload @since LibreOffice 5.3 */ template<typename T1, typename T2> - OStringBuffer & operator =(OStringConcat<T1, T2> const & concat) { + OStringBuffer & operator =(OStringConcat<T1, T2> && concat) { sal_Int32 const n = concat.length(); if (n >= nCapacity) { ensureCapacity(n + 16); //TODO: check for overflow @@ -549,7 +549,7 @@ public: @internal */ template< typename T1, typename T2 > - OStringBuffer& append( const OStringConcat< T1, T2 >& c ) + OStringBuffer& append( OStringConcat< T1, T2 >&& c ) { sal_Int32 l = c.length(); if( l == 0 ) diff --git a/include/rtl/string.hxx b/include/rtl/string.hxx index e113c264fc32..ead2af45863e 100644 --- a/include/rtl/string.hxx +++ b/include/rtl/string.hxx @@ -26,6 +26,7 @@ #include <cstddef> #include <new> #include <ostream> +#include <utility> #include <string.h> #include "rtl/textenc.h" @@ -266,7 +267,7 @@ public: @internal */ template< typename T1, typename T2 > - OString( const OStringConcat< T1, T2 >& c ) + OString( OStringConcat< T1, T2 >&& c ) { const sal_Int32 l = c.length(); pData = rtl_string_alloc( l ); @@ -367,7 +368,7 @@ public: @internal */ template< typename T1, typename T2 > - OString& operator+=( const OStringConcat< T1, T2 >& c ) & { + OString& operator+=( OStringConcat< T1, T2 >&& c ) & { sal_Int32 l = c.length(); if( l == 0 ) return *this; @@ -379,7 +380,7 @@ public: return *this; } template<typename T1, typename T2> void operator +=( - OStringConcat<T1, T2> const &) && = delete; + OStringConcat<T1, T2> &&) && = delete; #endif /** @@ -1839,9 +1840,9 @@ struct ToStringHelper< OStringLiteral > */ template< typename charT, typename traits, typename T1, typename T2 > inline std::basic_ostream<charT, traits> & operator <<( - std::basic_ostream<charT, traits> & stream, const OStringConcat< T1, T2 >& concat) + std::basic_ostream<charT, traits> & stream, OStringConcat< T1, T2 >&& concat) { - return stream << OString( concat ); + return stream << OString( std::move(concat) ); } #endif diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx index 16ca211d3f5b..1a40eeee8832 100644 --- a/include/rtl/ustrbuf.hxx +++ b/include/rtl/ustrbuf.hxx @@ -208,7 +208,7 @@ public: @internal */ template< typename T1, typename T2 > - OUStringBuffer( const OUStringConcat< T1, T2 >& c ) + OUStringBuffer( OUStringConcat< T1, T2 >&& c ) { const sal_Int32 l = c.length(); nCapacity = l + 16; @@ -313,7 +313,7 @@ public: #if defined LIBO_INTERNAL_ONLY /** @overload @since LibreOffice 5.3 */ template<typename T1, typename T2> - OUStringBuffer & operator =(OUStringConcat<T1, T2> const & concat) { + OUStringBuffer & operator =(OUStringConcat<T1, T2> && concat) { sal_Int32 const n = concat.length(); if (n >= nCapacity) { ensureCapacity(n + 16); //TODO: check for overflow @@ -631,7 +631,7 @@ public: @internal */ template< typename T1, typename T2 > - OUStringBuffer& append( const OUStringConcat< T1, T2 >& c ) + OUStringBuffer& append( OUStringConcat< T1, T2 >&& c ) { sal_Int32 l = c.length(); if( l == 0 ) diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx index 74b46fdc0887..f5aa1312b000 100644 --- a/include/rtl/ustring.hxx +++ b/include/rtl/ustring.hxx @@ -26,6 +26,7 @@ #include <cstddef> #include <new> #include <ostream> +#include <utility> #include <string.h> #include "rtl/ustring.h" @@ -391,7 +392,7 @@ public: @internal */ template< typename T1, typename T2 > - OUString( const OUStringConcat< T1, T2 >& c ) + OUString( OUStringConcat< T1, T2 >&& c ) { const sal_Int32 l = c.length(); pData = rtl_uString_alloc( l ); @@ -598,7 +599,7 @@ public: @internal */ template< typename T1, typename T2 > - OUString& operator+=( const OUStringConcat< T1, T2 >& c ) & { + OUString& operator+=( OUStringConcat< T1, T2 >&& c ) & { sal_Int32 l = c.length(); if( l == 0 ) return *this; @@ -610,7 +611,7 @@ public: return *this; } template<typename T1, typename T2> void operator +=( - OUStringConcat<T1, T2> const &) && = delete; + OUStringConcat<T1, T2> &&) && = delete; #endif /** @@ -3584,9 +3585,9 @@ struct ToStringHelper< OUStringLiteral > */ template< typename charT, typename traits, typename T1, typename T2 > inline std::basic_ostream<charT, traits> & operator <<( - std::basic_ostream<charT, traits> & stream, const OUStringConcat< T1, T2 >& concat) + std::basic_ostream<charT, traits> & stream, OUStringConcat< T1, T2 >&& concat) { - return stream << OUString( concat ); + return stream << OUString( std::move(concat) ); } /// @endcond |