accessibility/source/standard/vclxaccessibleedit.cxx  |    2 -
 basic/source/runtime/methods.cxx                      |    5 ++--
 basic/source/runtime/runtime.cxx                      |    2 -
 basic/source/sbx/sbxstr.cxx                           |    2 -
 connectivity/source/drivers/file/FStringFunctions.cxx |   21 ++++++++----------
 editeng/source/editeng/impedit3.cxx                   |    4 +--
 sc/source/core/data/table4.cxx                        |    4 +--
 7 files changed, 20 insertions(+), 20 deletions(-)

New commits:
commit 5bd55c22c1bd3e4daed48f9c162557dc9161d4ac
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Sun Feb 6 07:09:38 2022 +0100
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sun Feb 6 13:13:49 2022 +0100

    We know the length here
    
    Change-Id: I630b7fbda7c9ebf578e74260a0d67eea32e9e429
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129549
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/accessibility/source/standard/vclxaccessibleedit.cxx 
b/accessibility/source/standard/vclxaccessibleedit.cxx
index 87cfcdb62f30..d41c29737d62 100644
--- a/accessibility/source/standard/vclxaccessibleedit.cxx
+++ b/accessibility/source/standard/vclxaccessibleedit.cxx
@@ -135,7 +135,7 @@ OUString VCLXAccessibleEdit::implGetText()
             sal_Unicode cEchoChar = pEdit->GetEchoChar();
             if ( !cEchoChar )
                 cEchoChar = '*';
-            OUStringBuffer sTmp;
+            OUStringBuffer sTmp(aText.getLength());
             aText = comphelper::string::padToLength(sTmp, aText.getLength(),
                 cEchoChar).makeStringAndClear();
         }
diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx
index fd0c0531168c..7113e6e34f4c 100644
--- a/basic/source/runtime/methods.cxx
+++ b/basic/source/runtime/methods.cxx
@@ -1610,8 +1610,9 @@ void SbRtl_Tab(StarBASIC *, SbxArray & rPar, bool)
         StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
     else
     {
-        OUStringBuffer aStr;
-        comphelper::string::padToLength(aStr, rPar.Get(1)->GetLong(), '\t');
+        const sal_Int32 nCount = std::max(rPar.Get(1)->GetLong(), 
sal_Int32(0));
+        OUStringBuffer aStr(nCount);
+        comphelper::string::padToLength(aStr, nCount, '\t');
         rPar.Get(0)->PutString(aStr.makeStringAndClear());
     }
 }
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index afc785e76b32..6cdc371d4147 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -4585,7 +4585,7 @@ void SbiRuntime::implHandleSbxFlags( SbxVariable* pVar, 
SbxDataType t, sal_uInt3
     if( bFixedString )
     {
         sal_uInt16 nCount = static_cast<sal_uInt16>( nOp2 >> 17 );      // len 
= all bits above 0x10000
-        OUStringBuffer aBuf;
+        OUStringBuffer aBuf(nCount);
         comphelper::string::padToLength(aBuf, nCount);
         pVar->PutString(aBuf.makeStringAndClear());
     }
diff --git a/basic/source/sbx/sbxstr.cxx b/basic/source/sbx/sbxstr.cxx
index 0c6fc19d514b..4e447bb600bb 100644
--- a/basic/source/sbx/sbxstr.cxx
+++ b/basic/source/sbx/sbxstr.cxx
@@ -302,7 +302,7 @@ SbxArray* StringToByteArray(const OUString& rStr)
 OUString ByteArrayToString(SbxArray* pArr)
 {
     sal_uInt32 nCount = pArr->Count();
-    OUStringBuffer aStrBuf;
+    OUStringBuffer aStrBuf((nCount + 1) / 2);
     sal_Unicode aChar = 0;
     for( sal_uInt32 i = 0 ; i < nCount ; i++ )
     {
diff --git a/connectivity/source/drivers/file/FStringFunctions.cxx 
b/connectivity/source/drivers/file/FStringFunctions.cxx
index 619c1a128dbf..94152bc5d01c 100644
--- a/connectivity/source/drivers/file/FStringFunctions.cxx
+++ b/connectivity/source/drivers/file/FStringFunctions.cxx
@@ -18,6 +18,8 @@
  */
 
 #include <file/FStringFunctions.hxx>
+
+#include <comphelper/string.hxx>
 #include <rtl/ustrbuf.hxx>
 
 using namespace connectivity;
@@ -61,7 +63,7 @@ ORowSetValue OOp_Char::operate(const 
std::vector<ORowSetValue>& lhs) const
     if (lhs.empty())
         return ORowSetValue();
 
-    OUStringBuffer sRet;
+    OUStringBuffer sRet(static_cast<sal_Int32>(lhs.size()));
     std::vector<ORowSetValue>::const_reverse_iterator aIter = lhs.rbegin();
     std::vector<ORowSetValue>::const_reverse_iterator aEnd = lhs.rend();
     for (; aIter != aEnd; ++aIter)
@@ -151,13 +153,9 @@ ORowSetValue OOp_Space::operate(const ORowSetValue& lhs) 
const
     if (lhs.isNull())
         return lhs;
 
-    const char c = ' ';
-    OUStringBuffer sRet;
-    sal_Int32 nCount = lhs.getInt32();
-    for (sal_Int32 i = 0; i < nCount; ++i)
-    {
-        sRet.appendAscii(&c, 1);
-    }
+    sal_Int32 nCount = std::max(lhs.getInt32(), sal_Int32(0));
+    OUStringBuffer sRet(nCount);
+    comphelper::string::padToLength(sRet, nCount, ' ');
     return sRet.makeStringAndClear();
 }
 
@@ -184,11 +182,12 @@ ORowSetValue OOp_Repeat::operate(const ORowSetValue& lhs, 
const ORowSetValue& rh
     if (lhs.isNull() || rhs.isNull())
         return lhs;
 
-    OUStringBuffer sRet;
-    sal_Int32 nCount = rhs.getInt32();
+    const OUString s = lhs.getString();
+    const sal_Int32 nCount = std::max(rhs.getInt32(), sal_Int32(0));
+    OUStringBuffer sRet(s.getLength() * nCount);
     for (sal_Int32 i = 0; i < nCount; ++i)
     {
-        sRet.append(lhs.getString());
+        sRet.append(s);
     }
     return sRet.makeStringAndClear();
 }
diff --git a/editeng/source/editeng/impedit3.cxx 
b/editeng/source/editeng/impedit3.cxx
index a0e4eb43b913..d8c7419ca2ea 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -3595,7 +3595,7 @@ void ImpEditEngine::Paint( OutputDevice& rOutDev, 
tools::Rectangle aClipRect, Po
                                                 aTmpFont.SetEscapement( 0 );
                                                 aTmpFont.SetPropr( 100 );
                                                 aTmpFont.SetPhysFont(rOutDev);
-                                                OUStringBuffer aBlanks;
+                                                OUStringBuffer 
aBlanks(nTextLen);
                                                 
comphelper::string::padToLength( aBlanks, nTextLen, ' ' );
                                                 Point aUnderlinePos( aOutPos );
                                                 if ( nOrientation )
@@ -3726,7 +3726,7 @@ void ImpEditEngine::Paint( OutputDevice& rOutDev, 
tools::Rectangle aClipRect, Po
                                     else if ( nChars == 2 )
                                         nChars = 3; // looks better
 
-                                    OUStringBuffer aBuf;
+                                    OUStringBuffer aBuf(nChars);
                                     comphelper::string::padToLength(aBuf, 
nChars, rTextPortion.GetExtraValue());
                                     OUString aText(aBuf.makeStringAndClear());
                                     aTmpFont.QuickDrawText( &rOutDev, aTmpPos, 
aText, 0, aText.getLength() );
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 272cb82322d7..88d4395eaced 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -124,9 +124,9 @@ OUString lcl_ValueString( sal_Int32 nValue, sal_uInt16 
nMinDigits )
         OUString aStr = OUString::number( std::abs( nValue ) );
         if ( aStr.getLength() < nMinDigits )
         {
-            OUStringBuffer aZero;
+            OUStringBuffer aZero(nMinDigits);
             comphelper::string::padToLength(aZero, nMinDigits - 
aStr.getLength(), '0');
-            aStr = aZero.makeStringAndClear() + aStr;
+            aStr = aZero.append(aStr).makeStringAndClear();
         }
         //  nMinDigits doesn't include the '-' sign -> add after inserting 
zeros
         if ( nValue < 0 )

Reply via email to