[PATCH xserver 2/4] hw/xwin: Fix -Wmaybe-uninitialized warning in winWindowProc

Jon Turney jon.turney at dronecode.org.uk
Wed Apr 19 13:36:53 UTC 2017


On 18/04/2017 22:08, Adam Jackson wrote:
> On Tue, 2017-04-18 at 11:53 +0100, Jon Turney wrote:
>> This is possibly an actual bug in failing to check we successfully retrieved
>> the monitor size before using it to set the X screen size.
>
> It is indeed.
>
>> @@ -261,6 +261,9 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
>>                              ErrorF("Monitor number %d no longer exists!\n",
>>                                     s_pScreenInfo->iMonitor);
>>                          }
>> +                        ErrorF("QueryMonitor %d failed!\n",
>> +                               s_pScreenInfo->iMonitor);
>> +
>
> This is inside if (QueryMonitor()), which returns true most of the
> time. It only returns false if the second argument is null (which it
> won't ever be since it's on the stack), and also ignores the return
> value from EnumDisplayMonitors. So basically you're now printing that
> it fails on every call.

Oops!

But yes, even if I'd managed to correctly put this in an else clause, 
this is pointless (and checking the return value of 
EnumDisplayMonitors() turns out the be not very useful either, see 
5940580f), so I'll drop that part, and maybe make a patch to make 
QueryMonitor() less insane later...

Thanks for catching this.

Amended patch attached.

-------------- next part --------------
From 4df504fda1a4a913f803b50da8081fe39927f50a Mon Sep 17 00:00:00 2001
From: Jon Turney <jon.turney at dronecode.org.uk>
Date: Wed, 19 Apr 2017 13:30:27 +0100
Subject: [PATCH xserver 2/4] hw/xwin: Fix -Wmaybe-uninitialized warning in
 winWindowProc
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This is possibly an actual bug in failing to check we successfuly retrieved
the monitor size before using it to set the X screen size.

../hw/xwin/winwndproc.c: In function ‘winWindowProc’:
../hw/xwin/winwndproc.c:283:55: warning: ‘dwHeight’ may be used uninitialized in this function [-Wmaybe-uninitialized]
../hw/xwin/winwndproc.c:240:32: note: ‘dwHeight’ was declared here
../hw/xwin/winwndproc.c:281:54: warning: ‘dwWidth’ may be used uninitialized in this function [-Wmaybe-uninitialized]
../hw/xwin/winwndproc.c:240:23: note: ‘dwWidth’ was declared here

Signed-off-by: Jon Turney <jon.turney at dronecode.org.uk>
---
 hw/xwin/winwndproc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hw/xwin/winwndproc.c b/hw/xwin/winwndproc.c
index 7236a95..ad9f1b3 100644
--- a/hw/xwin/winwndproc.c
+++ b/hw/xwin/winwndproc.c
@@ -237,7 +237,7 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                                                                     fMultiWindow
 #endif
                 )) {
-                DWORD dwWidth, dwHeight;
+                DWORD dwWidth = 0, dwHeight = 0;
 
                 if (s_pScreenInfo->fMultipleMonitors) {
                     /* resize to new virtual desktop size */
@@ -273,8 +273,9 @@ winWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                  */
 
                 /* Set screen size to match new size, if it is different to current */
-                if ((s_pScreenInfo->dwWidth != dwWidth) ||
-                    (s_pScreenInfo->dwHeight != dwHeight)) {
+                if (((dwWidth != 0) && (dwHeight != 0)) &&
+                    ((s_pScreenInfo->dwWidth != dwWidth) ||
+                     (s_pScreenInfo->dwHeight != dwHeight))) {
                     winDoRandRScreenSetSize(s_pScreen,
                                             dwWidth,
                                             dwHeight,
-- 
2.8.3



More information about the xorg-devel mailing list