[PATCH xserver 04/11] dix: Don't limit GCperDepth to MAXFORMATS

Adam Jackson ajax at redhat.com
Fri Dec 9 19:52:31 UTC 2016


GCperDepth is the scratch GC pool. When we look up a scratch GC we match
against depth and pay no attention to MAXFORMATS, so we can size the
array dynamically based on how many depths are supported.

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 dix/gc.c             | 15 +++++++--------
 include/scrnintstr.h |  2 +-
 2 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/dix/gc.c b/dix/gc.c
index 73bb3b4..5d68ae9 100644
--- a/dix/gc.c
+++ b/dix/gc.c
@@ -825,10 +825,10 @@ FreeGCperDepth(int screenNum)
     pScreen = screenInfo.screens[screenNum];
     ppGC = pScreen->GCperDepth;
 
-    for (i = 0; i < pScreen->numDepths; i++) {
+    for (i = 0; i < pScreen->numDepths; i++)
         (void) FreeGC(ppGC[i], (XID) 0);
-        ppGC[i] = NULL;
-    }
+    free(ppGC);
+    pScreen->GCperDepth = NULL;
 }
 
 Bool
@@ -840,20 +840,19 @@ CreateGCperDepth(int screenNum)
     GCPtr *ppGC;
 
     pScreen = screenInfo.screens[screenNum];
-    ppGC = pScreen->GCperDepth;
-
-    /* Make sure we don't overflow GCperDepth[] */
-    if (pScreen->numDepths > MAXFORMATS)
-        return FALSE;
+    ppGC = calloc(pScreen->numDepths, sizeof(GCPtr));
 
     pDepth = pScreen->allowedDepths;
     for (i = 0; i < pScreen->numDepths; i++, pDepth++) {
         if (!(ppGC[i] = CreateScratchGC(pScreen, pDepth->depth))) {
             for (; i >= 0; i--)
                 (void) FreeGC(ppGC[i], (XID) 0);
+            free(ppGC);
             return FALSE;
         }
     }
+
+    pScreen->GCperDepth = ppGC;
     return TRUE;
 }
 
diff --git a/include/scrnintstr.h b/include/scrnintstr.h
index f174549..965821a 100644
--- a/include/scrnintstr.h
+++ b/include/scrnintstr.h
@@ -503,7 +503,7 @@ typedef struct _Screen {
     short minInstalledCmaps, maxInstalledCmaps;
     char backingStoreSupport, saveUnderSupport;
     unsigned long whitePixel, blackPixel;
-    GCPtr GCperDepth[MAXFORMATS + 1];
+    GCPtr *GCperDepth;
     /* next field is a stipple to use as default in a GC.  we don't build
      * default tiles of all depths because they are likely to be of a color
      * different from the default fg pixel, so we don't win anything by
-- 
2.9.3



More information about the xorg-devel mailing list