Blame SOURCES/0001-xt-Work-around-a-compiler-issue-with-gcc-10.patch

983011
From f3079e509c5cf60042ae2261499ee13b6b02498a Mon Sep 17 00:00:00 2001
983011
From: Adam Jackson <ajax@redhat.com>
983011
Date: Thu, 6 Feb 2020 13:45:35 -0500
983011
Subject: [PATCH] xt: Work around a compiler issue with gcc 10
983011
983011
GRABEXT() is used to look up a pointer that sometimes lives just past
983011
the end of an XtServerGrabRec. Whether it's really there or not depends
983011
on XtServerGrabRec::hasExt. In a couple of places, we build those
983011
structs on the stack and pass them to other functions; such structs
983011
always have hasExt == 0, so GRABEXT would never get called in practice.
983011
However, there exists a bug in gcc 10 - more or less difficult to hit,
983011
depending on your compiler options and architecture - where it would not
983011
notice that the dereference after GRABEXT is dead code, at which point
983011
it looks like you're dereferencing one past the end of the array, which
983011
is illegal, and you you get:
983011
983011
    PassivGrab.c:292:35: error: array subscript 0 is outside array bounds
983011
    of 'XtServerGrabRec[1]' {aka 'struct _XtServerGrabRec[1]'}
983011
    [-Werror=array-bounds]
983011
983011
As a completely stupid workaround, build those on-stack structs as
983011
arrays of two, so that the (dead) dereference looks like it's pointing
983011
into the dummy member of the array. This is almost certainly a compiler
983011
bug and I don't encourage merging this patch upstream, but if you need
983011
to build libXt with gcc 10 absolutely right this second, here it is.
983011
983011
For details on the gcc issue, see:
983011
983011
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93582
983011
---
983011
 src/PassivGrab.c | 24 ++++++++++++------------
983011
 1 file changed, 12 insertions(+), 12 deletions(-)
983011
983011
diff --git a/src/PassivGrab.c b/src/PassivGrab.c
983011
index bece0d9..b174d40 100644
983011
--- a/src/PassivGrab.c
983011
+++ b/src/PassivGrab.c
983011
@@ -553,7 +553,7 @@ XtServerGrabPtr _XtCheckServerGrabsOnWidget (
983011
     _XtBoolean		isKeyboard)
983011
 {
983011
     register XtServerGrabPtr grab;
983011
-    XtServerGrabRec 	tempGrab;
983011
+    XtServerGrabRec 	tempGrab[2];
983011
     XtServerGrabPtr	*passiveListPtr;
983011
     XtPerWidgetInput	pwi;
983011
 
983011
@@ -577,13 +577,13 @@ XtServerGrabPtr _XtCheckServerGrabsOnWidget (
983011
     /* Take only the lower thirteen bits as modifier state.  The X Keyboard
983011
      * Extension may be representing keyboard group state in two upper bits.
983011
      */
983011
-    tempGrab.widget = widget;
983011
-    tempGrab.keybut = (KeyCode) event->xkey.keycode; /* also xbutton.button */
983011
-    tempGrab.modifiers = event->xkey.state & 0x1FFF; /*also xbutton.state*/
983011
-    tempGrab.hasExt = False;
983011
+    tempGrab[0].widget = widget;
983011
+    tempGrab[0].keybut = (KeyCode) event->xkey.keycode; /* also xbutton.button */
983011
+    tempGrab[0].modifiers = event->xkey.state & 0x1FFF; /*also xbutton.state*/
983011
+    tempGrab[0].hasExt = False;
983011
 
983011
     for (grab = *passiveListPtr; grab; grab = grab->next) {
983011
-	if (GrabMatchesSecond(&tempGrab, grab))
983011
+	if (GrabMatchesSecond(tempGrab, grab))
983011
 	    return (grab);
983011
     }
983011
     return (XtServerGrabPtr)NULL;
983011
@@ -775,17 +775,17 @@ void   UngrabKeyOrButton (
983011
     Modifiers	modifiers,
983011
     Boolean	isKeyboard)
983011
 {
983011
-    XtServerGrabRec 	tempGrab;
983011
+    XtServerGrabRec 	tempGrab[2];
983011
     XtPerWidgetInput	pwi;
983011
 
983011
     XtCheckSubclass(widget, coreWidgetClass,
983011
 		    "in XtUngrabKey or XtUngrabButton");
983011
 
983011
     /* Build a temporary grab list entry */
983011
-    tempGrab.widget = widget;
983011
-    tempGrab.modifiers = (unsigned short) modifiers;
983011
-    tempGrab.keybut = (KeyCode) keyOrButton;
983011
-    tempGrab.hasExt = False;
983011
+    tempGrab[0].widget = widget;
983011
+    tempGrab[0].modifiers = (unsigned short) modifiers;
983011
+    tempGrab[0].keybut = (KeyCode) keyOrButton;
983011
+    tempGrab[0].hasExt = False;
983011
 
983011
     LOCK_PROCESS;
983011
     pwi = _XtGetPerWidgetInput(widget, FALSE);
983011
@@ -817,7 +817,7 @@ void   UngrabKeyOrButton (
983011
 
983011
     /* Delete all entries which are encompassed by the specified grab. */
983011
     DeleteServerGrabFromList(isKeyboard ? &pwi->keyList : &pwi->ptrList,
983011
-			     &tempGrab);
983011
+			     tempGrab);
983011
 }
983011
 
983011
 void  XtGrabKey (
983011
-- 
983011
2.23.0
983011