Skip to content

WIP: xt: Work around a compiler issue with gcc 10

Adam Jackson requested to merge ajax/libxt:gcc-10-s390x-workaround into master

GRABEXT() is used to look up a pointer that sometimes lives just past the end of an XtServerGrabRec. Whether it's really there or not depends on XtServerGrabRec::hasExt. In a couple of places, we build those structs on the stack and pass them to other functions; such structs always have hasExt == 0, so GRABEXT would never get called in practice. However, there exists a bug in gcc 10 - more or less difficult to hit, depending on your compiler options and architecture - where it would not notice that the dereference after GRABEXT is dead code, at which point it looks like you're dereferencing one past the end of the array, which is illegal, and you you get:

PassivGrab.c:292:35: error: array subscript 0 is outside array bounds
of 'XtServerGrabRec[1]' {aka 'struct _XtServerGrabRec[1]'}

As a completely stupid workaround, build those on-stack structs as arrays of two, so that the (dead) dereference looks like it's pointing into the dummy member of the array. This is almost certainly a compiler bug and I don't encourage merging this patch upstream, but if you need to build libXt with gcc 10 absolutely right this second, here it is.

For details on the gcc issue, see:

Merge request reports