[PATCH] xf86Mode: Don't make the mode name a "const char *"

Jasper St. Pierre jstpierre at mecheye.net
Thu Apr 23 14:06:03 PDT 2015


"const" implies that the pointer is in static memory, and could easily
make people not free it after calling xf86DuplicateMode out of
confusion. Change it back to a "char *", and fix up callers to respect
that.
---
 hw/xfree86/common/xf86Mode.c    |  2 +-
 hw/xfree86/common/xf86VidMode.c | 18 +++++++++---------
 hw/xfree86/common/xf86str.h     |  2 +-
 hw/xfree86/fbdevhw/fbdevhw.c    |  2 +-
 hw/xfree86/modes/xf86Modes.c    |  2 +-
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/hw/xfree86/common/xf86Mode.c b/hw/xfree86/common/xf86Mode.c
index 9a5550f..495262e 100644
--- a/hw/xfree86/common/xf86Mode.c
+++ b/hw/xfree86/common/xf86Mode.c
@@ -1998,7 +1998,7 @@ xf86DeleteMode(DisplayModePtr * modeList, DisplayModePtr mode)
             mode->next->prev = mode->prev;
     }
 
-    free((void *) mode->name);
+    free(mode->name);
     free(mode);
 }
 
diff --git a/hw/xfree86/common/xf86VidMode.c b/hw/xfree86/common/xf86VidMode.c
index e708b27..efd4453 100644
--- a/hw/xfree86/common/xf86VidMode.c
+++ b/hw/xfree86/common/xf86VidMode.c
@@ -421,22 +421,22 @@ VidModeSetCrtcForMode(int scrnIndex, void *mode)
 }
 
 Bool
-VidModeAddModeline(int scrnIndex, void *mode)
+VidModeAddModeline(int scrnIndex, void *mode_)
 {
     ScrnInfoPtr pScrn;
+    DisplayModePtr mode = mode_;
 
     if ((mode == NULL) || (!VidModeAvailable(scrnIndex)))
         return FALSE;
 
     pScrn = xf86Screens[scrnIndex];
 
-    ((DisplayModePtr) mode)->name = strdup(""); /* freed by deletemode */
-    ((DisplayModePtr) mode)->status = MODE_OK;
-    ((DisplayModePtr) mode)->next = pScrn->modes->next;
-    ((DisplayModePtr) mode)->prev = pScrn->modes;
-    pScrn->modes->next = (DisplayModePtr) mode;
-    if (((DisplayModePtr) mode)->next != NULL)
-        ((DisplayModePtr) mode)->next->prev = (DisplayModePtr) mode;
+    mode->status = MODE_OK;
+    mode->next = pScrn->modes->next;
+    mode->prev = pScrn->modes;
+    pScrn->modes->next = mode;
+    if (mode->next != NULL)
+        mode->next->prev = mode;
 
     return TRUE;
 }
@@ -533,7 +533,7 @@ VidModeCreateMode(void)
 
     mode = malloc(sizeof(DisplayModeRec));
     if (mode != NULL) {
-        mode->name = "";
+        mode->name = strdup(""); /* freed by deletemode */
         mode->VScan = 1;        /* divides refresh rate. default = 1 */
         mode->Private = NULL;
         mode->next = mode;
diff --git a/hw/xfree86/common/xf86str.h b/hw/xfree86/common/xf86str.h
index 643a65d..1d1c54b 100644
--- a/hw/xfree86/common/xf86str.h
+++ b/hw/xfree86/common/xf86str.h
@@ -145,7 +145,7 @@ typedef enum {
 typedef struct _DisplayModeRec {
     struct _DisplayModeRec *prev;
     struct _DisplayModeRec *next;
-    const char *name;           /* identifier for the mode */
+    char *name;                 /* identifier for the mode */
     ModeStatus status;
     int type;
 
diff --git a/hw/xfree86/fbdevhw/fbdevhw.c b/hw/xfree86/fbdevhw/fbdevhw.c
index 8cd2079..25baf2b 100644
--- a/hw/xfree86/fbdevhw/fbdevhw.c
+++ b/hw/xfree86/fbdevhw/fbdevhw.c
@@ -392,7 +392,7 @@ fbdevHWInit(ScrnInfoPtr pScrn, struct pci_device *pPci, char *device)
 
     /* we can use the current settings as "buildin mode" */
     fbdev2xfree_timing(&fPtr->var, &fPtr->buildin);
-    fPtr->buildin.name = "current";
+    fPtr->buildin.name = (char *) "current";
     fPtr->buildin.next = &fPtr->buildin;
     fPtr->buildin.prev = &fPtr->buildin;
     fPtr->buildin.type |= M_T_BUILTIN;
diff --git a/hw/xfree86/modes/xf86Modes.c b/hw/xfree86/modes/xf86Modes.c
index 43b2233..d56abda 100644
--- a/hw/xfree86/modes/xf86Modes.c
+++ b/hw/xfree86/modes/xf86Modes.c
@@ -131,7 +131,7 @@ xf86SetModeDefaultName(DisplayModePtr mode)
     Bool interlaced = ! !(mode->Flags & V_INTERLACE);
     char *tmp;
 
-    free((void *) mode->name);
+    free(mode->name);
 
     XNFasprintf(&tmp, "%dx%d%s", mode->HDisplay, mode->VDisplay,
                 interlaced ? "i" : "");
-- 
2.1.0



More information about the xorg-devel mailing list