[PATCH 12/37] Clean up warnings in DIX

Keith Packard keithp at keithp.com
Sun Nov 17 00:01:37 PST 2013


As usual, mostly const char changes. However, filter_device_events had
a potentially uninitialized value, 'raw', which I added a bunch of
checks for. I suspect most of those are 'can't happen', but it's hard
to see that inside the function.

Signed-off-by: Keith Packard <keithp at keithp.com>
---
 Xext/xvmc.c          |  4 ++--
 Xext/xvmcext.h       |  4 ++--
 dix/dispatch.c       |  4 ++--
 dix/dixfonts.c       | 31 +++++++++++++++++--------------
 dix/events.c         |  5 +++++
 dix/extension.c      | 14 +++++++-------
 dix/getevents.c      | 11 ++++++-----
 dix/globals.c        |  8 ++++----
 dix/window.c         |  6 +++---
 include/closestr.h   |  2 +-
 include/dix.h        |  5 ++++-
 include/dixfont.h    |  6 +++---
 include/extnsionst.h |  4 ++--
 include/gcstruct.h   |  4 ++--
 include/globals.h    |  2 +-
 include/opaque.h     |  6 +++---
 16 files changed, 64 insertions(+), 52 deletions(-)

diff --git a/Xext/xvmc.c b/Xext/xvmc.c
index 5f0123b..2235fd5 100644
--- a/Xext/xvmc.c
+++ b/Xext/xvmc.c
@@ -800,8 +800,8 @@ XvMCFindXvImage(XvPortPtr pPort, CARD32 id)
 }
 
 int
-xf86XvMCRegisterDRInfo(ScreenPtr pScreen, char *name,
-                       char *busID, int major, int minor, int patchLevel)
+xf86XvMCRegisterDRInfo(ScreenPtr pScreen, const char *name,
+                       const char *busID, int major, int minor, int patchLevel)
 {
     XvMCScreenPtr pScreenPriv = XVMC_GET_PRIVATE(pScreen);
 
diff --git a/Xext/xvmcext.h b/Xext/xvmcext.h
index 2201d7b..832e443 100644
--- a/Xext/xvmcext.h
+++ b/Xext/xvmcext.h
@@ -91,8 +91,8 @@ extern _X_EXPORT int XvMCScreenInit(ScreenPtr pScreen,
 
 extern _X_EXPORT XvImagePtr XvMCFindXvImage(XvPortPtr pPort, CARD32 id);
 
-extern _X_EXPORT int xf86XvMCRegisterDRInfo(ScreenPtr pScreen, char *name,
-                                            char *busID, int major, int minor,
+extern _X_EXPORT int xf86XvMCRegisterDRInfo(ScreenPtr pScreen, const char *name,
+                                            const char *busID, int major, int minor,
                                             int patchLevel);
 
 #endif                          /* _XVMC_H */
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 4fecfea..d229ed9 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -469,7 +469,7 @@ Dispatch(void)
 }
 
 static int VendorRelease = VENDOR_RELEASE;
-static char *VendorString = VENDOR_NAME;
+static const char *VendorString = VENDOR_NAME;
 
 void
 SetVendorRelease(int release)
@@ -478,7 +478,7 @@ SetVendorRelease(int release)
 }
 
 void
-SetVendorString(char *string)
+SetVendorString(const char *string)
 {
     VendorString = string;
 }
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 2e34d37..57177ac 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -128,7 +128,7 @@ dixGetGlyphs(FontPtr font, unsigned long count, unsigned char *chars,
  * adding RT_FONT prevents conflict with default cursor font
  */
 Bool
-SetDefaultFont(char *defaultfontname)
+SetDefaultFont(const char *defaultfontname)
 {
     int err;
     FontPtr pf;
@@ -224,7 +224,7 @@ FreeFPE(FontPathElementPtr fpe)
     fpe->refcount--;
     if (fpe->refcount == 0) {
         (*fpe_functions[fpe->type].free_fpe) (fpe);
-        free(fpe->name);
+        free((void *) fpe->name);
         free(fpe);
     }
 }
@@ -288,7 +288,7 @@ doOpenFont(ClientPtr client, OFclosurePtr c)
 
         if (err == FontNameAlias && alias) {
             newlen = strlen(alias);
-            newname = (char *) realloc(c->fontname, newlen);
+            newname = (char *) realloc((char *) c->fontname, newlen);
             if (!newname) {
                 err = AllocError;
                 break;
@@ -368,14 +368,14 @@ doOpenFont(ClientPtr client, OFclosurePtr c)
         FreeFPE(c->fpe_list[i]);
     }
     free(c->fpe_list);
-    free(c->fontname);
+    free((void *) c->fontname);
     free(c);
     return TRUE;
 }
 
 int
 OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname,
-         char *pfontname)
+         const char *pfontname)
 {
     OFclosurePtr c;
     int i;
@@ -426,7 +426,7 @@ OpenFont(ClientPtr client, XID fid, Mask flags, unsigned lenfname,
      */
     c->fpe_list = malloc(sizeof(FontPathElementPtr) * num_fpes);
     if (!c->fpe_list) {
-        free(c->fontname);
+        free((void *) c->fontname);
         free(c);
         return BadAlloc;
     }
@@ -1537,7 +1537,7 @@ ImageText(ClientPtr client, DrawablePtr pDraw, GC * pGC, int nChars,
 
 /* does the necessary magic to figure out the fpe type */
 static int
-DetermineFPEType(char *pathname)
+DetermineFPEType(const char *pathname)
 {
     int i;
 
@@ -1633,21 +1633,23 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
             }
             /* if error or can't do it, act like it's a new one */
             if (!fpe) {
+                char *name;
                 fpe = malloc(sizeof(FontPathElementRec));
                 if (!fpe) {
                     err = BadAlloc;
                     goto bail;
                 }
-                fpe->name = malloc(len + 1);
-                if (!fpe->name) {
+                name = malloc(len + 1);
+                if (!name) {
                     free(fpe);
                     err = BadAlloc;
                     goto bail;
                 }
                 fpe->refcount = 1;
 
-                strncpy(fpe->name, (char *) cp, (int) len);
-                fpe->name[len] = '\0';
+                strncpy(name, (char *) cp, (int) len);
+                name[len] = '\0';
+                fpe->name = name;
                 fpe->name_length = len;
                 fpe->type = DetermineFPEType(fpe->name);
                 if (fpe->type == -1)
@@ -1660,7 +1662,7 @@ SetFontPathElements(int npaths, unsigned char *paths, int *bad, Bool persist)
                             ("[dix] Could not init font path element %s, removing from list!\n",
                              fpe->name);
                     }
-                    free(fpe->name);
+                    free((void *) fpe->name);
                     free(fpe);
                 }
             }
@@ -1712,9 +1714,10 @@ SetFontPath(ClientPtr client, int npaths, unsigned char *paths)
 }
 
 int
-SetDefaultFontPath(char *path)
+SetDefaultFontPath(const char *path)
 {
-    char *temp_path, *start, *end;
+    const char *start, *end;
+    char *temp_path;
     unsigned char *cp, *pp, *nump, *newpath;
     int num = 1, len, err, size = 0, bad;
 
diff --git a/dix/events.c b/dix/events.c
index 4632bb7..67bfac2 100644
--- a/dix/events.c
+++ b/dix/events.c
@@ -2671,6 +2671,9 @@ DeliverOneEvent(InternalEvent *event, DeviceIntPtr dev, enum InputLevel level,
     case CORE:
         rc = EventToCore(event, &xE, &count);
         break;
+    default:
+        rc = BadImplementation;
+        break;
     }
 
     if (rc == Success) {
@@ -3828,6 +3831,8 @@ MatchForType(const GrabPtr grab, GrabPtr tmp, enum InputLevel level,
         match = CORE_MATCH;
         ignore_device = TRUE;
         break;
+    default:
+        return NO_MATCH;
     }
 
     tmp->grabtype = grabtype;
diff --git a/dix/extension.c b/dix/extension.c
index 6380db3..ede4bf5 100644
--- a/dix/extension.c
+++ b/dix/extension.c
@@ -96,7 +96,7 @@ AddExtension(const char *name, int NumEvents, int NumErrors,
     }
     ext->name = strdup(name);
     ext->num_aliases = 0;
-    ext->aliases = (char **) NULL;
+    ext->aliases = (const char **) NULL;
     if (!ext->name) {
         dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION);
         free(ext);
@@ -106,7 +106,7 @@ AddExtension(const char *name, int NumEvents, int NumErrors,
     newexts = (ExtensionEntry **) realloc(extensions,
                                           (i + 1) * sizeof(ExtensionEntry *));
     if (!newexts) {
-        free(ext->name);
+        free((void *) ext->name);
         dixFreePrivates(ext->devPrivates, PRIVATE_EXTENSION);
         free(ext);
         return ((ExtensionEntry *) NULL);
@@ -147,12 +147,12 @@ Bool
 AddExtensionAlias(const char *alias, ExtensionEntry * ext)
 {
     char *name;
-    char **aliases;
+    const char **aliases;
 
     if (!ext)
         return FALSE;
-    aliases = (char **) realloc(ext->aliases,
-                                (ext->num_aliases + 1) * sizeof(char *));
+    aliases = realloc(ext->aliases,
+                      (ext->num_aliases + 1) * sizeof(char *));
     if (!aliases)
         return FALSE;
     ext->aliases = aliases;
@@ -229,9 +229,9 @@ CloseDownExtensions(void)
         if (extensions[i]->CloseDown)
             extensions[i]->CloseDown(extensions[i]);
         NumExtensions = i;
-        free(extensions[i]->name);
+        free((void *) extensions[i]->name);
         for (j = extensions[i]->num_aliases; --j >= 0;)
-            free(extensions[i]->aliases[j]);
+            free((void *) extensions[i]->aliases[j]);
         free(extensions[i]->aliases);
         dixFreePrivates(extensions[i]->devPrivates, PRIVATE_EXTENSION);
         free(extensions[i]);
diff --git a/dix/getevents.c b/dix/getevents.c
index 14b65ca..646c723 100644
--- a/dix/getevents.c
+++ b/dix/getevents.c
@@ -1382,10 +1382,10 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
 {
     int num_events = 1;
     DeviceEvent *event;
-    RawDeviceEvent *raw;
+    RawDeviceEvent *raw = NULL;
     double screenx = 0.0, screeny = 0.0;        /* desktop coordinate system */
     double devx = 0.0, devy = 0.0;      /* desktop-wide in device coords */
-    int sx, sy;                         /* for POINTER_SCREEN */
+    int sx = 0, sy = 0;                 /* for POINTER_SCREEN */
     ValuatorMask mask;
     ScreenPtr scr;
     int num_barrier_events = 0;
@@ -1437,7 +1437,7 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
 
         transformAbsolute(pDev, &mask);
         clipAbsolute(pDev, &mask);
-        if ((flags & POINTER_NORAW) == 0)
+        if ((flags & POINTER_NORAW) == 0 && raw)
             set_raw_valuators(raw, &mask, raw->valuators.data);
     }
     else {
@@ -1445,7 +1445,7 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
 
         if (flags & POINTER_ACCELERATE)
             accelPointer(pDev, &mask, ms);
-        if ((flags & POINTER_NORAW) == 0)
+        if ((flags & POINTER_NORAW) == 0 && raw)
             set_raw_valuators(raw, &mask, raw->valuators.data);
 
         moveRelative(pDev, flags, &mask);
@@ -1512,7 +1512,8 @@ fill_pointer_events(InternalEvent *events, DeviceIntPtr pDev, int type,
     event_set_root_coordinates(event, screenx - scr->x, screeny - scr->y);
 
     if (flags & POINTER_EMULATED) {
-        raw->flags = XIPointerEmulated;
+        if (raw)
+            raw->flags = XIPointerEmulated;
         event->flags = XIPointerEmulated;
     }
 
diff --git a/dix/globals.c b/dix/globals.c
index ad9145b..9738e9c 100644
--- a/dix/globals.c
+++ b/dix/globals.c
@@ -112,9 +112,9 @@ int defaultScreenSaverAllowExposures = DEFAULT_SCREEN_SAVER_EXPOSURES;
 Bool screenSaverSuspended = FALSE;
 #endif
 
-char *defaultFontPath = COMPILEDDEFAULTFONTPATH;
-char *defaultTextFont = COMPILEDDEFAULTFONT;
-char *defaultCursorFont = COMPILEDCURSORFONT;
+const char *defaultFontPath = COMPILEDDEFAULTFONTPATH;
+const char *defaultTextFont = COMPILEDDEFAULTFONT;
+const char *defaultCursorFont = COMPILEDCURSORFONT;
 FontPtr defaultFont;            /* not declared in dix.h to avoid including font.h in
                                    every compilation of dix code */
 CursorPtr rootCursor;
@@ -126,7 +126,7 @@ TimeStamp currentTime;
 int defaultColorVisualClass = -1;
 int monitorResolution = 0;
 
-char *display;
+const char *display;
 int displayfd;
 char *ConnectionInfo;
 
diff --git a/dix/window.c b/dix/window.c
index 92df1eb..4465638 100644
--- a/dix/window.c
+++ b/dix/window.c
@@ -227,7 +227,7 @@ log_window_info(WindowPtr pWin, int depth)
 
     win_name = get_window_name(pWin);
     ErrorF("win 0x%.8x (%s), [%d, %d] to [%d, %d]",
-           pWin->drawable.id,
+           (unsigned) pWin->drawable.id,
            win_name ? win_name : "no name",
            pWin->drawable.x, pWin->drawable.y,
            pWin->drawable.x + pWin->drawable.width,
@@ -240,7 +240,7 @@ log_window_info(WindowPtr pWin, int depth)
         ErrorF(" (%s compositing: pixmap %x)",
                (pWin->redirectDraw == RedirectDrawAutomatic) ?
                "automatic" : "manual",
-               pScreen->GetWindowPixmap(pWin)->drawable.id);
+               (unsigned) pScreen->GetWindowPixmap(pWin)->drawable.id);
 #endif
 
     switch (pWin->visibility) {
@@ -283,7 +283,7 @@ PrintWindowTree(void)
     for (scrnum = 0; scrnum < screenInfo.numScreens; scrnum++) {
         pScreen = screenInfo.screens[scrnum];
         ErrorF("[dix] Dumping windows for screen %d (pixmap %x):\n", scrnum,
-               pScreen->GetScreenPixmap(pScreen)->drawable.id);
+               (unsigned) pScreen->GetScreenPixmap(pScreen)->drawable.id);
         pWin = pScreen->root;
         depth = 1;
         while (pWin) {
diff --git a/include/closestr.h b/include/closestr.h
index c6aa129..d762891 100644
--- a/include/closestr.h
+++ b/include/closestr.h
@@ -47,7 +47,7 @@ typedef struct _OFclosure {
     Mask flags;
 
 /* XXX -- get these from request buffer instead? */
-    char *origFontName;
+    const char *origFontName;
     int origFontNameLen;
     XID fontid;
     char *fontname;
diff --git a/include/dix.h b/include/dix.h
index fa7ccd4..7362e07 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -289,7 +289,10 @@ extern _X_EXPORT void
 SetVendorRelease(int release);
 
 extern _X_EXPORT void
-SetVendorString(char *string);
+SetVendorString(const char *string);
+
+int
+dix_main(int argc, char *argv[], char *envp[]);
 
 /* events.c */
 
diff --git a/include/dixfont.h b/include/dixfont.h
index 0a5f105..0598311 100644
--- a/include/dixfont.h
+++ b/include/dixfont.h
@@ -34,7 +34,7 @@ SOFTWARE.
 
 typedef struct _DIXFontProp *DIXFontPropPtr;
 
-extern _X_EXPORT Bool SetDefaultFont(char * /*defaultfontname */ );
+extern _X_EXPORT Bool SetDefaultFont(const char * /*defaultfontname */ );
 
 extern _X_EXPORT void QueueFontWakeup(FontPathElementPtr /*fpe */ );
 
@@ -48,7 +48,7 @@ extern _X_EXPORT int OpenFont(ClientPtr /*client */ ,
                               XID /*fid */ ,
                               Mask /*flags */ ,
                               unsigned /*lenfname */ ,
-                              char * /*pfontname */ );
+                              const char * /*pfontname */ );
 
 extern _X_EXPORT int CloseFont(pointer /*pfont */ ,
                                XID /*fid */ );
@@ -99,7 +99,7 @@ extern _X_EXPORT int SetFontPath(ClientPtr /*client */ ,
                                  int /*npaths */ ,
                                  unsigned char * /*paths */ );
 
-extern _X_EXPORT int SetDefaultFontPath(char * /*path */ );
+extern _X_EXPORT int SetDefaultFontPath(const char * /*path */ );
 
 extern _X_EXPORT int GetFontPath(ClientPtr client,
                                  int *count,
diff --git a/include/extnsionst.h b/include/extnsionst.h
index e825236..126807d 100644
--- a/include/extnsionst.h
+++ b/include/extnsionst.h
@@ -58,14 +58,14 @@ typedef struct _ExtensionEntry {
     int index;
     void (*CloseDown) (         /* called at server shutdown */
                           struct _ExtensionEntry * /* extension */ );
-    char *name;                 /* extension name */
+    const char *name;           /* extension name */
     int base;                   /* base request number */
     int eventBase;
     int eventLast;
     int errorBase;
     int errorLast;
     int num_aliases;
-    char **aliases;
+    const char **aliases;
     pointer extPrivate;
     unsigned short (*MinorOpcode) (     /* called for errors */
                                       ClientPtr /* client */ );
diff --git a/include/gcstruct.h b/include/gcstruct.h
index 7621ceb..253593f 100644
--- a/include/gcstruct.h
+++ b/include/gcstruct.h
@@ -276,8 +276,8 @@ typedef struct _GC {
     pointer clientClip;
     unsigned long stateChanges; /* masked with GC_<kind> */
     unsigned long serialNumber;
-    GCFuncs *funcs;
-    GCOps *ops;
+    const GCFuncs *funcs;
+    const GCOps *ops;
     PrivateRec *devPrivates;
     /*
      * The following were moved here from private storage to allow device-
diff --git a/include/globals.h b/include/globals.h
index 7786987..858c9a3 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -18,7 +18,7 @@ extern _X_EXPORT CARD32 ScreenSaverInterval;
 extern _X_EXPORT Bool screenSaverSuspended;
 #endif
 
-extern _X_EXPORT char *defaultFontPath;
+extern _X_EXPORT const char *defaultFontPath;
 extern _X_EXPORT int monitorResolution;
 extern _X_EXPORT int defaultColorVisualClass;
 
diff --git a/include/opaque.h b/include/opaque.h
index b76ab6e..73d40c3 100644
--- a/include/opaque.h
+++ b/include/opaque.h
@@ -33,8 +33,8 @@ from The Open Group.
 
 #include "globals.h"
 
-extern _X_EXPORT char *defaultTextFont;
-extern _X_EXPORT char *defaultCursorFont;
+extern _X_EXPORT const char *defaultTextFont;
+extern _X_EXPORT const char *defaultCursorFont;
 extern _X_EXPORT int MaxClients;
 extern _X_EXPORT volatile char isItTimeToYield;
 extern _X_EXPORT volatile char dispatchException;
@@ -49,7 +49,7 @@ extern _X_EXPORT int ScreenSaverBlanking;
 extern _X_EXPORT int ScreenSaverAllowExposures;
 extern _X_EXPORT int defaultScreenSaverBlanking;
 extern _X_EXPORT int defaultScreenSaverAllowExposures;
-extern _X_EXPORT char *display;
+extern _X_EXPORT const char *display;
 extern _X_EXPORT int displayfd;
 
 extern _X_EXPORT int defaultBackingStore;
-- 
1.8.4.2



More information about the xorg-devel mailing list