• Matt Turner's avatar
    dix: Assert noPanoramiXExtension is false in PanoramiX code · 61aa40ae
    Matt Turner authored
    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: #590Signed-off-by: Matt Turner's avatarMatt Turner <mattst88@gmail.com>
    61aa40ae
Name
Last commit
Last update
.gitlab-ci Loading commit data...
Xext Loading commit data...
Xi Loading commit data...
composite Loading commit data...
config Loading commit data...
damageext Loading commit data...
dbe Loading commit data...
dix Loading commit data...
doc Loading commit data...
dri3 Loading commit data...
exa Loading commit data...
fb Loading commit data...
glamor Loading commit data...
glx Loading commit data...
hw Loading commit data...
include Loading commit data...
m4 Loading commit data...
man Loading commit data...
mi Loading commit data...
miext Loading commit data...
os Loading commit data...
present Loading commit data...
pseudoramiX Loading commit data...
randr Loading commit data...
record Loading commit data...
render Loading commit data...
test Loading commit data...
xfixes Loading commit data...
xkb Loading commit data...
.appveyor.yml Loading commit data...
.dir-locals.el Loading commit data...
.gitignore Loading commit data...
.gitlab-ci.yml Loading commit data...
.travis.yml Loading commit data...
COPYING Loading commit data...
Makefile.am Loading commit data...
README.md Loading commit data...
autogen.sh Loading commit data...
buildDateTime.h.in Loading commit data...
buildDateTime.sh Loading commit data...
configure.ac Loading commit data...
devbook.am Loading commit data...
docbook.am Loading commit data...
manpages.am Loading commit data...
meson.build Loading commit data...
meson_options.txt Loading commit data...
xorg-server.m4 Loading commit data...
xorg-server.pc.in Loading commit data...
xserver.ent.in Loading commit data...