desktop/source/app/cmdlineargs.cxx | 2 - include/rtl/strbuf.hxx | 34 ++++++++++++++++----------------- include/rtl/ustrbuf.hxx | 33 +++++++++++++++----------------- sw/source/core/fields/authfld.cxx | 2 - vcl/source/filter/ipdf/pdfdocument.cxx | 2 - 5 files changed, 36 insertions(+), 37 deletions(-)
New commits: commit 58f533029b5cbd31993f2c667b16d3b487258e85 Author: Stephan Bergmann <[email protected]> AuthorDate: Wed Apr 13 11:01:42 2022 +0200 Commit: Stephan Bergmann <[email protected]> CommitDate: Wed Apr 13 21:46:48 2022 +0200 Clean up O[U]StringBuffer ctors taking a length parameter For !LIBO_INTERNAL_ONLY, go back to the state before d91d98a53612a972de368186415aa48698e074d9 "fix gcc-4.0.1 and/or 32bit build for string literals" of having just a sal_Int32 overload. (For !LIBO_INTERNAL_ONLY, the current state was confusing, as the existence of further overloads depended on __cplusplus >= 201103L.) And for LIBO_INTERNAL_ONLY: * Have overloads for all integral types, with an assert checking that they do not use out-of-bounds length arguments. (The std::make_unsigned_t dance in the assert is needed to avoid signed/unsigned mismatch warnings as seen at least with MSVC.) This removes the need for explicitly casting arguments that are larger than (unsigned) int. (And I cleaned up two such places that I had become aware of with the abandoned previous attempt <https://gerrit.libreoffice.org/c/core/+/132825> "Let O[U]StringBuffer ctors take sal_Int32 length parameters"; there may be more places to clean up, though.) * Have deleted overloads for all integral types that are not actually integer types. (This excludes signed char and unsigned char, as at least > OUStringBuffer aBuf( rToken.GetByte()); in ScTokenConversion::ConvertToTokenSequence in sc/source/ui/unoobj/tokenuno.cxx does a legitimate call with an argument of type sal_Int8 aka signed char.) Change-Id: I2df77429f25b74f19cc3de5064e6fd982e87b05e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132951 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx index 95f00cb097bc..0a9d21e3caae 100644 --- a/desktop/source/app/cmdlineargs.cxx +++ b/desktop/source/app/cmdlineargs.cxx @@ -219,7 +219,7 @@ CommandLineEvent CheckWebQuery(/* in,out */ OUString& arg, CommandLineEvent curE if (!SkipNewline(pPos)) return curEvt; - OStringBuffer aResult(static_cast<unsigned int>(nRead)); + OStringBuffer aResult(nRead); do { const char* pPos1 = pPos; diff --git a/include/rtl/strbuf.hxx b/include/rtl/strbuf.hxx index 7434b2f653a8..89301a088d34 100644 --- a/include/rtl/strbuf.hxx +++ b/include/rtl/strbuf.hxx @@ -27,6 +27,7 @@ #include <cassert> #include <cstring> +#include <limits> #include "rtl/strbuf.h" #include "rtl/string.hxx" @@ -35,6 +36,7 @@ #ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" #include "rtl/stringconcat.hxx" #include <string_view> +#include <type_traits> #endif #ifdef RTL_STRING_UNITTEST @@ -99,31 +101,29 @@ public: @param length the initial capacity. */ - explicit OStringBuffer(int length) + explicit OStringBuffer(sal_Int32 length) : pData(NULL) , nCapacity( length ) { rtl_string_new_WithLength( &pData, length ); } -#if __cplusplus >= 201103L - explicit OStringBuffer(unsigned int length) - : OStringBuffer(static_cast<int>(length)) - { - } -#if SAL_TYPES_SIZEOFLONG == 4 - // additional overloads for sal_Int32 sal_uInt32 - explicit OStringBuffer(long length) - : OStringBuffer(static_cast<int>(length)) - { - } - explicit OStringBuffer(unsigned long length) - : OStringBuffer(static_cast<int>(length)) +#if defined LIBO_INTERNAL_ONLY + template<typename T> + explicit OStringBuffer(T length, std::enable_if_t<std::is_integral_v<T>, int> = 0) + : OStringBuffer(static_cast<sal_Int32>(length)) { + assert( + length >= 0 + && static_cast<std::make_unsigned_t<T>>(length) + <= static_cast<std::make_unsigned_t<sal_Int32>>( + std::numeric_limits<sal_Int32>::max())); } -#endif - // avoid obvious bugs + // avoid (obvious) bugs + explicit OStringBuffer(bool) = delete; explicit OStringBuffer(char) = delete; - explicit OStringBuffer(sal_Unicode) = delete; + explicit OStringBuffer(wchar_t) = delete; + explicit OStringBuffer(char16_t) = delete; + explicit OStringBuffer(char32_t) = delete; #endif /** diff --git a/include/rtl/ustrbuf.hxx b/include/rtl/ustrbuf.hxx index fa8fa511071a..bb1bb9cef366 100644 --- a/include/rtl/ustrbuf.hxx +++ b/include/rtl/ustrbuf.hxx @@ -33,6 +33,7 @@ #if defined LIBO_INTERNAL_ONLY #include <string_view> +#include <type_traits> #endif #include "rtl/ustrbuf.h" @@ -100,31 +101,29 @@ public: @param length the initial capacity. */ - explicit OUStringBuffer(int length) + explicit OUStringBuffer(sal_Int32 length) : pData(NULL) , nCapacity( length ) { rtl_uString_new_WithLength( &pData, length ); } -#if __cplusplus >= 201103L - explicit OUStringBuffer(unsigned int length) - : OUStringBuffer(static_cast<int>(length)) - { - } -#if SAL_TYPES_SIZEOFLONG == 4 - // additional overloads for sal_Int32 sal_uInt32 - explicit OUStringBuffer(long length) - : OUStringBuffer(static_cast<int>(length)) - { - } - explicit OUStringBuffer(unsigned long length) - : OUStringBuffer(static_cast<int>(length)) +#if defined LIBO_INTERNAL_ONLY + template<typename T> + explicit OUStringBuffer(T length, std::enable_if_t<std::is_integral_v<T>, int> = 0) + : OUStringBuffer(static_cast<sal_Int32>(length)) { + assert( + length >= 0 + && static_cast<std::make_unsigned_t<T>>(length) + <= static_cast<std::make_unsigned_t<sal_Int32>>( + std::numeric_limits<sal_Int32>::max())); } -#endif - // avoid obvious bugs + // avoid (obvious) bugs + explicit OUStringBuffer(bool) = delete; explicit OUStringBuffer(char) = delete; - explicit OUStringBuffer(sal_Unicode) = delete; + explicit OUStringBuffer(wchar_t) = delete; + explicit OUStringBuffer(char16_t) = delete; + explicit OUStringBuffer(char32_t) = delete; #endif /** diff --git a/sw/source/core/fields/authfld.cxx b/sw/source/core/fields/authfld.cxx index 5d4b72ba551b..f81feebca3d1 100644 --- a/sw/source/core/fields/authfld.cxx +++ b/sw/source/core/fields/authfld.cxx @@ -737,7 +737,7 @@ bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ ) if(!(rAny >>= aParam)) return false; - OUStringBuffer sBuf(AUTH_FIELD_LOCAL_URL); + OUStringBuffer sBuf(+AUTH_FIELD_LOCAL_URL); comphelper::string::padToLength(sBuf, AUTH_FIELD_LOCAL_URL, TOX_STYLE_DELIMITER); OUString sToSet(sBuf.makeStringAndClear()); for(const PropertyValue& rParam : std::as_const(aParam)) diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx b/vcl/source/filter/ipdf/pdfdocument.cxx index 3d005a45ff2e..dd6728faff08 100644 --- a/vcl/source/filter/ipdf/pdfdocument.cxx +++ b/vcl/source/filter/ipdf/pdfdocument.cxx @@ -2061,7 +2061,7 @@ OUString PDFDocument::DecodeHexStringUTF16BE(PDFHexStringElement const& rElement { return {}; } - OUStringBuffer buf(static_cast<unsigned int>(encoded.size() - 2)); + OUStringBuffer buf(encoded.size() - 2); for (size_t i = 2; i < encoded.size(); i += 2) { buf.append(sal_Unicode((static_cast<sal_uInt16>(encoded[i]) << 8) | encoded[i + 1]));
