[Libreoffice-commits] core.git: vcl/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Mon Mar 29 13:35:32 UTC 2021


 vcl/source/control/edit.cxx |   20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)

New commits:
commit ae2c96cd29e1900ffa9c6909af701a9198a08afb
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Mar 29 12:11:45 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon Mar 29 15:34:53 2021 +0200

    cid#1474054 Uninitialized scalar variable
    
    this code was introduced with
    
    commit 57b5ed51d46fd5673dfe35125ceffa71d39f133d
    Date:   Mon May 6 14:20:11 2013 +0900
    
        Support IMR_QUERYCHARPOSITION in Writer and Calc.
    
    we're not bounds checking (nIndex+mpIMEInfos->nPos) so I have
    to assume that the range is considered safe in which case there's
    no point in checking aText.isEmpty(). If the range is unsafe then
    we needs proper bounds checking not just the isEmpty case
    
    Change-Id: I75dd3e0938a7fa892d700addcc93e6a4990fde4d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113311
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index 82e650e88b63..87aafd4bcb3b 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -2131,31 +2131,21 @@ void Edit::Command( const CommandEvent& rCEvt )
         if (mpIMEInfos && mpIMEInfos->nLen > 0)
         {
             OUString aText = ImplGetText();
-            tools::Long   nDXBuffer[256];
-            std::unique_ptr<tools::Long[]> pDXBuffer;
-            tools::Long*  pDX = nDXBuffer;
+            std::vector<tools::Long> aDX(2*(aText.getLength()+1));
 
-            if( !aText.isEmpty() )
-            {
-                if( o3tl::make_unsigned(2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
-                {
-                    pDXBuffer.reset(new tools::Long[2*(aText.getLength()+1)]);
-                    pDX = pDXBuffer.get();
-                }
+            GetCaretPositions( aText, aDX.data(), 0, aText.getLength() );
 
-                GetCaretPositions( aText, pDX, 0, aText.getLength() );
-            }
             tools::Long    nTH = GetTextHeight();
             Point   aPos( mnXOffset, ImplGetTextYPosition() );
 
-            std::unique_ptr<tools::Rectangle[]> aRects(new tools::Rectangle[ mpIMEInfos->nLen ]);
+            std::vector<tools::Rectangle> aRects(mpIMEInfos->nLen);
             for ( int nIndex = 0; nIndex < mpIMEInfos->nLen; ++nIndex )
             {
                 tools::Rectangle aRect( aPos, Size( 10, nTH ) );
-                aRect.SetLeft( pDX[2*(nIndex+mpIMEInfos->nPos)] + mnXOffset + ImplGetExtraXOffset() );
+                aRect.SetLeft( aDX[2*(nIndex+mpIMEInfos->nPos)] + mnXOffset + ImplGetExtraXOffset() );
                 aRects[ nIndex ] = aRect;
             }
-            SetCompositionCharRect( aRects.get(), mpIMEInfos->nLen );
+            SetCompositionCharRect(aRects.data(), mpIMEInfos->nLen);
         }
     }
     else


More information about the Libreoffice-commits mailing list