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.lunak@collabora.com>
This commit is contained in:
Luboš Luňák 2022-06-09 18:23:44 +02:00
parent 930ba0c1ec
commit b7b06f28d5

View file

@ -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)