summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Turner <mattst88@gmail.com>2019-08-09 20:22:29 -0700
committerMatt Turner <mattst88@gmail.com>2019-10-29 15:01:20 -0700
commitfada61e89dd1f20fe8e2e0fb9e4baefb45b4b848 (patch)
tree9ba30bc0f30e6b0c66d7e29d461a3082729023c3
parente815db543450c38d1d4ec03184b8e82fa0a37498 (diff)
dix: Assert noPanoramiXExtension is false in PanoramiX code
When compiling with link time optimization, GCC thinks it's discovered undefined behavior: events.c: In function 'XineramaConfineCursorToWindow': events.c:609:13: warning: iteration 2147483647 invokes undefined behavior [-Waggressive-loop-optimizations] events.c:609:11: note: within this loop events.c:605:49: warning: array subscript -1 is below array bounds of 'struct _Window *[16]' [-Warray-bounds] events.c:606:31: warning: array subscript -1 is below array bounds of 'struct _Screen *[16]' [-Warray-bounds] events.c:610:39: warning: array subscript -2 is below array bounds of 'struct _Screen *[16]' [-Warray-bounds] events.c:617:38: warning: array subscript -2 is below array bounds of 'struct _Window *[16]' [-Warray-bounds] events.c:619:35: warning: array subscript -2 is below array bounds of 'struct _Screen *[16]' [-Warray-bounds] This results from i = PanoramiXNumScreens - 1; RegionCopy(&pSprite->Reg1, &pSprite->windows[i]->borderSize); off_x = screenInfo.screens[i]->x; off_y = screenInfo.screens[i]->y; where GCC believes that PanoramiXNumScreens might be 0. Unfortunately GCC is just smart enough to be an annoyance because this case is not actually possible: XineramaConfineCursorToWindow() is only called when noPanoramiXExtension is false, and if noPanoramiXExtension is false then PanoramiXNumScreens must be >1 (see PanoramiXExtensionInit()). So, add an assert(!noPanoramiXExtension), which to my surprise provides GCC with information even in release builds and lets GCC understand that the code is not doing anything that is undefined behavior. I chose this solution instead of the proposed assert(i >= 0) because the same pattern occurs in CheckVirtualMotion() but is inside an 'if (!noPanoramiXExtension)' and does not generate any warnings. Fixes: xorg/xserver#590 Signed-off-by: Matt Turner <mattst88@gmail.com> (cherry picked from commit 61aa40aeb3d4efefda47f245ed4b83a1a19b1d4c)
-rw-r--r--dix/events.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/dix/events.c b/dix/events.c
index d3a33ea3f..c02a0594a 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -597,6 +597,8 @@ XineramaConfineCursorToWindow(DeviceIntPtr pDev,
int x, y, off_x, off_y, i;
+ assert(!noPanoramiXExtension);
+
if (!XineramaSetWindowPntrs(pDev, pWin))
return;