vcl/source/window/syswin.cxx |   29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

New commits:
commit b7b06f28d5728c2c33c073df35ac0c3bcc51e583
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Thu Jun 9 18:23:44 2022 +0200
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Mon Jun 13 10:36:15 2022 +0200

    avoid uninitialized data when handling WindowState
    
    I get valgrind reports when I start LO with kf5 backend and
    a maximized window, since in that case position and size are not
    set (since the maximized state makes them irrelevant). The semantics
    here seem to conflict, the caller of GetWindowState() sets flags
    to say what data it wants, and SalFrame::GetWindowState() sets flags
    to say what data it provides, but as can be seen here those aren't
    necessarily the same. So actually use only those flags that are
    in both sets.
    
    Change-Id: I4559baab90d6f465382560549d52431b28119b3f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135563
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx
index fa053499d623..113b2da02689 100644
--- a/vcl/source/window/syswin.cxx
+++ b/vcl/source/window/syswin.cxx
@@ -755,7 +755,10 @@ void SystemWindow::GetWindowState(vcl::WindowData& rData) 
const
         return;
 
     if ( mbSysChild )
+    {
+        rData.setMask( vcl::WindowDataMask::NONE );
         return;
+    }
 
     const vcl::Window* pWindow = this;
     while ( pWindow->mpWindowImpl->mpBorderWindow )
@@ -764,9 +767,11 @@ void SystemWindow::GetWindowState(vcl::WindowData& rData) 
const
     if ( pWindow->mpWindowImpl->mbFrame )
     {
         vcl::WindowData aState;
-        aState.setMask(vcl::WindowDataMask::All);
         if ( mpWindowImpl->mpFrame->GetWindowState( &aState ) )
         {
+            // Limit mask only to what we've received, the rest is not set.
+            nValidMask &= aState.mask();
+            rData.setMask( nValidMask );
             if ( nValidMask & vcl::WindowDataMask::X )
                 rData.setX( aState.x() );
             if ( nValidMask & vcl::WindowDataMask::Y )
@@ -775,26 +780,14 @@ void SystemWindow::GetWindowState(vcl::WindowData& rData) 
const
                 rData.setWidth( aState.width() );
             if ( nValidMask & vcl::WindowDataMask::Height )
                 rData.setHeight( aState.height() );
-            if ( aState.mask() & vcl::WindowDataMask::MaximizedX )
-            {
+            if ( nValidMask & vcl::WindowDataMask::MaximizedX )
                 rData.SetMaximizedX( aState.GetMaximizedX() );
-                nValidMask |= vcl::WindowDataMask::MaximizedX;
-            }
-            if ( aState.mask() & vcl::WindowDataMask::MaximizedY )
-            {
+            if ( nValidMask & vcl::WindowDataMask::MaximizedY )
                 rData.SetMaximizedY( aState.GetMaximizedY() );
-                nValidMask |= vcl::WindowDataMask::MaximizedY;
-            }
-            if ( aState.mask() & vcl::WindowDataMask::MaximizedWidth )
-            {
+            if ( nValidMask & vcl::WindowDataMask::MaximizedWidth )
                 rData.SetMaximizedWidth( aState.GetMaximizedWidth() );
-                nValidMask |= vcl::WindowDataMask::MaximizedWidth;
-            }
-            if ( aState.mask() & vcl::WindowDataMask::MaximizedHeight )
-            {
+            if ( nValidMask & vcl::WindowDataMask::MaximizedHeight )
                 rData.SetMaximizedHeight( aState.GetMaximizedHeight() );
-                nValidMask |= vcl::WindowDataMask::MaximizedHeight;
-            }
             if ( nValidMask & vcl::WindowDataMask::State )
             {
                 // #94144# allow Minimize again, should be masked out when 
read from configuration
@@ -814,6 +807,8 @@ void SystemWindow::GetWindowState(vcl::WindowData& rData) 
const
         Size    aSize = GetSizePixel();
         vcl::WindowState nState = vcl::WindowState::NONE;
 
+        nValidMask &= vcl::WindowDataMask::PosSizeState;
+        rData.setMask( nValidMask );
         if (nValidMask & vcl::WindowDataMask::X)
             rData.setX(aPos.X());
         if (nValidMask & vcl::WindowDataMask::Y)

Reply via email to