[PATCH 5/7] input: un-constify dev->name

Peter Hutterer peter.hutterer at who-t.net
Wed Jan 29 15:51:18 PST 2014


Fallout from fecc7eb1cf66db64728ee2d68cd9443df7e70879, and reverts most of the
rest of that patch.

The device name is allocated and may even change during PreInit. The const
warnings came from the test codes, the correct fix here is to fix the test
code.

touch.c: In function ‘touch_init’:
touch.c:254:14: warning: assignment discards ‘const’ qualifier from pointer target type [enabled by default]
     dev.name = "test device";

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 Xi/extinit.c       |  4 ++--
 dix/devices.c      |  2 +-
 include/inputstr.h |  2 +-
 test/touch.c       | 20 +++++++++++++++-----
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/Xi/extinit.c b/Xi/extinit.c
index 9ebd733..26c628c 100644
--- a/Xi/extinit.c
+++ b/Xi/extinit.c
@@ -1169,8 +1169,8 @@ IResetProc(ExtensionEntry * unused)
     EventSwapVector[DevicePropertyNotify] = NotImplemented;
     RestoreExtensionEvents();
 
-    free((void *) xi_all_devices.name);
-    free((void *) xi_all_master_devices.name);
+    free(xi_all_devices.name);
+    free(xi_all_master_devices.name);
 
     XIBarrierReset();
 }
diff --git a/dix/devices.c b/dix/devices.c
index 45de713..a875f03 100644
--- a/dix/devices.c
+++ b/dix/devices.c
@@ -955,7 +955,7 @@ CloseDevice(DeviceIntPtr dev)
     while (dev->xkb_interest)
         XkbRemoveResourceClient((DevicePtr) dev, dev->xkb_interest->resource);
 
-    free((void *) dev->name);
+    free(dev->name);
 
     classes = (ClassesPtr) &dev->key;
     FreeAllDeviceClasses(classes);
diff --git a/include/inputstr.h b/include/inputstr.h
index dfcf7c3..f6cfb04 100644
--- a/include/inputstr.h
+++ b/include/inputstr.h
@@ -542,7 +542,7 @@ typedef struct _DeviceIntRec {
     GrabInfoRec deviceGrab;     /* grab on the device */
     int type;                   /* MASTER_POINTER, MASTER_KEYBOARD, SLAVE */
     Atom xinput_type;
-    const char *name;
+    char *name;
     int id;
     KeyClassPtr key;
     ValuatorClassPtr valuator;
diff --git a/test/touch.c b/test/touch.c
index df1db11..a232e60 100644
--- a/test/touch.c
+++ b/test/touch.c
@@ -40,7 +40,7 @@ touch_grow_queue(void)
     int i;
 
     memset(&dev, 0, sizeof(dev));
-    dev.name = "test device";
+    dev.name = strdup("test device");
     dev.id = 2;
     dev.valuator = &val;
     val.numAxes = 5;
@@ -82,6 +82,8 @@ touch_grow_queue(void)
         assert(t->client_id == 0);
         assert(t->ddx_id == 0);
     }
+
+    free(dev.name);
 }
 
 static void
@@ -95,7 +97,7 @@ touch_find_ddxid(void)
     int i;
 
     memset(&dev, 0, sizeof(dev));
-    dev.name = "test device";
+    dev.name = strdup("test device");
     dev.id = 2;
     dev.valuator = &val;
     val.numAxes = 5;
@@ -150,6 +152,8 @@ touch_find_ddxid(void)
     ProcessWorkQueue();
     ti = TouchFindByDDXID(&dev, 40, TRUE);
     assert(ti == &dev.last.touches[size]);
+
+    free(dev.name);
 }
 
 static void
@@ -164,7 +168,7 @@ touch_begin_ddxtouch(void)
     int size = 5;
 
     memset(&dev, 0, sizeof(dev));
-    dev.name = "test device";
+    dev.name = strdup("test device");
     dev.id = 2;
     dev.valuator = &val;
     val.numAxes = 5;
@@ -195,6 +199,8 @@ touch_begin_ddxtouch(void)
     assert(ti->client_id > last_client_id);
     assert(!ti->emulate_pointer);
     last_client_id = ti->client_id;
+
+    free(dev.name);
 }
 
 static void
@@ -212,7 +218,7 @@ touch_begin_touch(void)
     screenInfo.screens[0] = &screen;
 
     memset(&dev, 0, sizeof(dev));
-    dev.name = "test device";
+    dev.name = strdup("test device");
     dev.id = 2;
 
     memset(&sprite, 0, sizeof(sprite));
@@ -237,6 +243,8 @@ touch_begin_touch(void)
     assert(ti->emulate_pointer);
 
     assert(touch.num_touches == 1);
+
+    free(dev.name);
 }
 
 static void
@@ -251,7 +259,7 @@ touch_init(void)
     screenInfo.screens[0] = &screen;
 
     memset(&dev, 0, sizeof(dev));
-    dev.name = "test device";
+    dev.name = strdup("test device");
 
     memset(&sprite, 0, sizeof(sprite));
     dev.spriteInfo = &sprite;
@@ -264,6 +272,8 @@ touch_init(void)
     rc = InitTouchClassDeviceStruct(&dev, 1, XIDirectTouch, 2);
     assert(rc == TRUE);
     assert(dev.touch);
+
+    free(dev.name);
 }
 
 int
-- 
1.8.4.2



More information about the xorg-devel mailing list