From 6307d60dd592f4b438f880d02bde9fd8d50ae264 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 29 Jan 2014 10:47:49 +1000 Subject: [PATCH 01/17] Xi: remove superfluous cast. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- Xi/listdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Xi/listdev.c b/Xi/listdev.c index 470fb52ee..6a10091d0 100644 --- a/Xi/listdev.c +++ b/Xi/listdev.c @@ -121,7 +121,7 @@ SizeDeviceInfo(DeviceIntPtr d, int *namesize, int *size) static void CopyDeviceName(char **namebuf, const char *name) { - char *nameptr = (char *) *namebuf; + char *nameptr = *namebuf; if (name) { *nameptr++ = strlen(name); From 2fc38d1e299587d25ca8225051e0ea9403164b15 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 29 Jan 2014 11:16:51 +1000 Subject: [PATCH 02/17] xkb: add a call to init an XkbRMLVOSet from const chars Just forcing everything to const char* is not helpful, compiler warnings are supposed to warn about broken code. Forcing everything to const when it clearly isn't less than ideal. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- hw/xfree86/common/xf86Config.c | 16 ++++++++-------- include/xkbrules.h | 10 +++++----- include/xkbsrv.h | 8 ++++++++ test/xkb.c | 18 +++++++++++------- xkb/xkbInit.c | 25 ++++++++++++++++++++----- 5 files changed, 52 insertions(+), 25 deletions(-) diff --git a/hw/xfree86/common/xf86Config.c b/hw/xfree86/common/xf86Config.c index 258b22bfe..542d5abf6 100644 --- a/hw/xfree86/common/xf86Config.c +++ b/hw/xfree86/common/xf86Config.c @@ -777,13 +777,7 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) MessageType from; const char *s; XkbRMLVOSet set; - - /* Default options. */ - set.rules = "base"; - set.model = "pc105"; - set.layout = "us"; - set.variant = NULL; - set.options = NULL; + const char *rules; /* * Merge the ServerLayout and ServerFlags options. The former have @@ -963,9 +957,15 @@ configServerFlags(XF86ConfFlagsPtr flagsconf, XF86OptionPtr layoutopts) * evdev rules set. */ #if defined(linux) if (!xf86Info.forceInputDevices) - set.rules = "evdev"; + rules = "evdev"; + else #endif + rules = "base"; + + /* Xkb default options. */ + XkbInitRules(&set, rules, "pc105", "us", NULL, NULL); XkbSetRulesDflts(&set); + XkbFreeRMLVOSet(&set, FALSE); xf86Info.useDefaultFontPath = TRUE; xf86Info.useDefaultFontPathFrom = X_DEFAULT; diff --git a/include/xkbrules.h b/include/xkbrules.h index 956eade0b..ab5b4b266 100644 --- a/include/xkbrules.h +++ b/include/xkbrules.h @@ -30,11 +30,11 @@ /***====================================================================***/ typedef struct _XkbRMLVOSet { - const char *rules; - const char *model; - const char *layout; - const char *variant; - const char *options; + char *rules; + char *model; + char *layout; + char *variant; + char *options; } XkbRMLVOSet; typedef struct _XkbRF_VarDefs { diff --git a/include/xkbsrv.h b/include/xkbsrv.h index 0b9ca06d9..e79979927 100644 --- a/include/xkbsrv.h +++ b/include/xkbsrv.h @@ -738,6 +738,14 @@ extern _X_EXPORT void XkbClearAllLatchesAndLocks(DeviceIntPtr /* dev */ , XkbEventCausePtr /* cause */ ); +extern _X_EXPORT void XkbInitRules(XkbRMLVOSet * /* rmlvo */, + const char * /* rules */, + const char * /* model */, + const char * /* layout */, + const char * /* variant */, + const char * /* options */ + ) ; + extern _X_EXPORT void XkbGetRulesDflts(XkbRMLVOSet * /* rmlvo */ ); diff --git a/test/xkb.c b/test/xkb.c index 955e72dff..9047f594c 100644 --- a/test/xkb.c +++ b/test/xkb.c @@ -82,15 +82,17 @@ xkb_get_rules_test(void) static void xkb_set_rules_test(void) { - XkbRMLVOSet rmlvo = { - .rules = "test-rules", - .model = "test-model", - .layout = "test-layout", - .variant = "test-variant", - .options = "test-options" - }; + XkbRMLVOSet rmlvo; XkbRMLVOSet rmlvo_new = { NULL }; + XkbInitRules(&rmlvo, "test-rules", "test-model", "test-layout", + "test-variant", "test-options"); + assert(rmlvo.rules); + assert(rmlvo.model); + assert(rmlvo.layout); + assert(rmlvo.variant); + assert(rmlvo.options); + XkbSetRulesDflts(&rmlvo); XkbGetRulesDflts(&rmlvo_new); @@ -106,6 +108,8 @@ xkb_set_rules_test(void) assert(strcmp(rmlvo.layout, rmlvo_new.layout) == 0); assert(strcmp(rmlvo.variant, rmlvo_new.variant) == 0); assert(strcmp(rmlvo.options, rmlvo_new.options) == 0); + + XkbFreeRMLVOSet(&rmlvo, FALSE); } /** diff --git a/xkb/xkbInit.c b/xkb/xkbInit.c index 22b971fc6..33420b6b6 100644 --- a/xkb/xkbInit.c +++ b/xkb/xkbInit.c @@ -129,11 +129,11 @@ XkbFreeRMLVOSet(XkbRMLVOSet * rmlvo, Bool freeRMLVO) if (!rmlvo) return; - free((void *) rmlvo->rules); - free((void *) rmlvo->model); - free((void *) rmlvo->layout); - free((void *) rmlvo->variant); - free((void *) rmlvo->options); + free(rmlvo->rules); + free(rmlvo->model); + free(rmlvo->layout); + free(rmlvo->variant); + free(rmlvo->options); if (freeRMLVO) free(rmlvo); @@ -206,6 +206,21 @@ XkbWriteRulesProp(ClientPtr client, void *closure) return TRUE; } +void +XkbInitRules(XkbRMLVOSet *rmlvo, + const char *rules, + const char *model, + const char *layout, + const char *variant, + const char *options) +{ + rmlvo->rules = rules ? xnfstrdup(rules) : NULL; + rmlvo->model = model ? xnfstrdup(model) : NULL; + rmlvo->layout = layout ? xnfstrdup(layout) : NULL; + rmlvo->variant = variant ? xnfstrdup(variant) : NULL; + rmlvo->options = options ? xnfstrdup(options) : NULL; +} + static void XkbSetRulesUsed(XkbRMLVOSet * rmlvo) { From ce3df579e3f24a169189b288230959527e059080 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 30 Jan 2014 08:50:06 +1000 Subject: [PATCH 03/17] input: un-constify InputAttributes Introduced in fecc7eb1cf66db64728ee2d68cd9443df7e70879 and reverts most of that but it's helpfully mixed with other stuff. InputAttributes are not const, they're strdup'd everywhere but the test code and freed properly. Revert the const char changes and fix the test up instead. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- config/udev.c | 14 ++++++------ dix/inpututils.c | 16 +++++++------- include/input.h | 12 +++++------ test/input.c | 56 ++++++++++++++++++++++++++---------------------- 4 files changed, 51 insertions(+), 47 deletions(-) diff --git a/config/udev.c b/config/udev.c index 436b8f038..68ed34843 100644 --- a/config/udev.c +++ b/config/udev.c @@ -242,16 +242,16 @@ device_added(struct udev_device *udev_device) free(config_info); input_option_free_list(&input_options); - free((void *) attrs.usb_id); - free((void *) attrs.pnp_id); - free((void *) attrs.product); - free((void *) attrs.device); - free((void *) attrs.vendor); + free(attrs.usb_id); + free(attrs.pnp_id); + free(attrs.product); + free(attrs.device); + free(attrs.vendor); if (attrs.tags) { - const char **tag = attrs.tags; + char **tag = attrs.tags; while (*tag) { - free((void *) *tag); + free(*tag); tag++; } free(attrs.tags); diff --git a/dix/inpututils.c b/dix/inpututils.c index 3e1d75fec..a10a7c761 100644 --- a/dix/inpututils.c +++ b/dix/inpututils.c @@ -351,7 +351,7 @@ DuplicateInputAttributes(InputAttributes * attrs) { InputAttributes *new_attr; int ntags = 0; - const char **tags, **new_tags; + char **tags, **new_tags; if (!attrs) return NULL; @@ -403,20 +403,20 @@ DuplicateInputAttributes(InputAttributes * attrs) void FreeInputAttributes(InputAttributes * attrs) { - const char **tags; + char **tags; if (!attrs) return; - free((void *) attrs->product); - free((void *) attrs->vendor); - free((void *) attrs->device); - free((void *) attrs->pnp_id); - free((void *) attrs->usb_id); + free(attrs->product); + free(attrs->vendor); + free(attrs->device); + free(attrs->pnp_id); + free(attrs->usb_id); if ((tags = attrs->tags)) while (*tags) - free((void *) *tags++); + free(*tags++); free(attrs->tags); free(attrs); diff --git a/include/input.h b/include/input.h index 455963f6a..6f047ee9c 100644 --- a/include/input.h +++ b/include/input.h @@ -221,12 +221,12 @@ typedef struct _InputOption InputOption; typedef struct _XI2Mask XI2Mask; typedef struct _InputAttributes { - const char *product; - const char *vendor; - const char *device; - const char *pnp_id; - const char *usb_id; - const char **tags; /* null-terminated */ + char *product; + char *vendor; + char *device; + char *pnp_id; + char *usb_id; + char **tags; /* null-terminated */ uint32_t flags; } InputAttributes; diff --git a/test/input.c b/test/input.c index aaa7a69d3..5813e6dc9 100644 --- a/test/input.c +++ b/test/input.c @@ -1101,7 +1101,7 @@ xi_unregister_handlers(void) static void cmp_attr_fields(InputAttributes * attr1, InputAttributes * attr2) { - const char **tags1, **tags2; + char **tags1, **tags2; assert(attr1 && attr2); assert(attr1 != attr2); @@ -1180,50 +1180,54 @@ cmp_attr_fields(InputAttributes * attr1, InputAttributes * attr2) static void dix_input_attributes(void) { - InputAttributes orig = { 0 }; + InputAttributes *orig; InputAttributes *new; - const char *tags[4] = { "tag1", "tag2", "tag2", NULL }; new = DuplicateInputAttributes(NULL); assert(!new); - new = DuplicateInputAttributes(&orig); - assert(memcmp(&orig, new, sizeof(InputAttributes)) == 0); + orig = calloc(1, sizeof(InputAttributes)); + assert(orig); - orig.product = "product name"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); + new = DuplicateInputAttributes(orig); + assert(memcmp(orig, new, sizeof(InputAttributes)) == 0); + + orig->product = xnfstrdup("product name"); + new = DuplicateInputAttributes(orig); + cmp_attr_fields(orig, new); FreeInputAttributes(new); - orig.vendor = "vendor name"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); + orig->vendor = xnfstrdup("vendor name"); + new = DuplicateInputAttributes(orig); + cmp_attr_fields(orig, new); FreeInputAttributes(new); - orig.device = "device path"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); + orig->device = xnfstrdup("device path"); + new = DuplicateInputAttributes(orig); + cmp_attr_fields(orig, new); FreeInputAttributes(new); - orig.pnp_id = "PnPID"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); + orig->pnp_id = xnfstrdup("PnPID"); + new = DuplicateInputAttributes(orig); + cmp_attr_fields(orig, new); FreeInputAttributes(new); - orig.usb_id = "USBID"; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); + orig->usb_id = xnfstrdup("USBID"); + new = DuplicateInputAttributes(orig); + cmp_attr_fields(orig, new); FreeInputAttributes(new); - orig.flags = 0xF0; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); + orig->flags = 0xF0; + new = DuplicateInputAttributes(orig); + cmp_attr_fields(orig, new); FreeInputAttributes(new); - orig.tags = tags; - new = DuplicateInputAttributes(&orig); - cmp_attr_fields(&orig, new); + orig->tags = xstrtokenize("tag1 tag2 tag3", " "); + new = DuplicateInputAttributes(orig); + cmp_attr_fields(orig, new); FreeInputAttributes(new); + + FreeInputAttributes(orig); } static void From 675f215af291135ee3ece5414e4a5a2e89bf4ed3 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 30 Jan 2014 08:52:32 +1000 Subject: [PATCH 04/17] Revert "os: xstrtokenize takes and returns const char * now" This reverts commit d0339a5c66846c9f14e3b584e34688520a0916ab. seriously, what the fuck? Are we making xstrdup() return a const char now too? Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- include/misc.h | 2 +- os/utils.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/misc.h b/include/misc.h index 165d42e85..17de71041 100644 --- a/include/misc.h +++ b/include/misc.h @@ -246,7 +246,7 @@ padding_for_int32(const int bytes) } -extern const char **xstrtokenize(const char *str, const char *separators); +extern char **xstrtokenize(const char *str, const char *separators); extern void FormatInt64(int64_t num, char *string); extern void FormatUInt64(uint64_t num, char *string); extern void FormatUInt64Hex(uint64_t num, char *string); diff --git a/os/utils.c b/os/utils.c index dc18a67b1..497779b52 100644 --- a/os/utils.c +++ b/os/utils.c @@ -1973,10 +1973,10 @@ CheckUserAuthorization(void) * Tokenize a string into a NULL terminated array of strings. Always returns * an allocated array unless an error occurs. */ -const char ** +char ** xstrtokenize(const char *str, const char *separators) { - const char **list, **nlist; + char **list, **nlist; char *tok, *tmp; unsigned num = 0, n; @@ -2004,7 +2004,7 @@ xstrtokenize(const char *str, const char *separators) error: free(tmp); for (n = 0; n < num; n++) - free((void *) list[n]); + free(list[n]); free(list); return NULL; } From 45f1d527f39a296104f2fa79a774446e7e1560e0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 30 Jan 2014 09:01:09 +1000 Subject: [PATCH 05/17] input: un-constify dev->name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Hans de Goede --- 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 9ebd733ab..26c628cbd 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 45de713ce..a875f03cc 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 dfcf7c383..f6cfb049d 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 df1db11de..981c694b6 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 = xnfstrdup("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 = xnfstrdup("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 = xnfstrdup("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 = xnfstrdup("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 = xnfstrdup("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 From a553444b5841522836f7437ebb96e40be270fd8b Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 30 Jan 2014 09:12:41 +1000 Subject: [PATCH 06/17] Revert "xfree86/parser: make strings in xf86MatchGroup const" This reverts commit f71de60355cc76810657f40c7b5461af86b34bf7. What warnings? Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- hw/xfree86/parser/InputClass.c | 24 ++++++++++++------------ hw/xfree86/parser/xf86Parser.h | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/hw/xfree86/parser/InputClass.c b/hw/xfree86/parser/InputClass.c index 24a124691..c2fbd22a7 100644 --- a/hw/xfree86/parser/InputClass.c +++ b/hw/xfree86/parser/InputClass.c @@ -63,7 +63,7 @@ xf86ConfigSymTabRec InputClassTab[] = { #define TOKEN_SEP "|" static void -add_group_entry(struct xorg_list *head, const char **values) +add_group_entry(struct xorg_list *head, char **values) { xf86MatchGroup *group; @@ -256,7 +256,7 @@ void xf86printInputClassSection(FILE * cf, XF86ConfInputClassPtr ptr) { const xf86MatchGroup *group; - const char *const *cur; + char *const *cur; while (ptr) { fprintf(cf, "Section \"InputClass\"\n"); @@ -362,7 +362,7 @@ xf86freeInputClassList(XF86ConfInputClassPtr ptr) while (ptr) { xf86MatchGroup *group, *next; - const char **list; + char **list; TestFree(ptr->identifier); TestFree(ptr->driver); @@ -370,55 +370,55 @@ xf86freeInputClassList(XF86ConfInputClassPtr ptr) xorg_list_for_each_entry_safe(group, next, &ptr->match_product, entry) { xorg_list_del(&group->entry); for (list = group->values; *list; list++) - free((void *) *list); + free(*list); free(group); } xorg_list_for_each_entry_safe(group, next, &ptr->match_vendor, entry) { xorg_list_del(&group->entry); for (list = group->values; *list; list++) - free((void *) *list); + free(*list); free(group); } xorg_list_for_each_entry_safe(group, next, &ptr->match_device, entry) { xorg_list_del(&group->entry); for (list = group->values; *list; list++) - free((void *) *list); + free(*list); free(group); } xorg_list_for_each_entry_safe(group, next, &ptr->match_os, entry) { xorg_list_del(&group->entry); for (list = group->values; *list; list++) - free((void *) *list); + free(*list); free(group); } xorg_list_for_each_entry_safe(group, next, &ptr->match_pnpid, entry) { xorg_list_del(&group->entry); for (list = group->values; *list; list++) - free((void *) *list); + free(*list); free(group); } xorg_list_for_each_entry_safe(group, next, &ptr->match_usbid, entry) { xorg_list_del(&group->entry); for (list = group->values; *list; list++) - free((void *) *list); + free(*list); free(group); } xorg_list_for_each_entry_safe(group, next, &ptr->match_driver, entry) { xorg_list_del(&group->entry); for (list = group->values; *list; list++) - free((void *) *list); + free(*list); free(group); } xorg_list_for_each_entry_safe(group, next, &ptr->match_tag, entry) { xorg_list_del(&group->entry); for (list = group->values; *list; list++) - free((void *) *list); + free(*list); free(group); } xorg_list_for_each_entry_safe(group, next, &ptr->match_layout, entry) { xorg_list_del(&group->entry); for (list = group->values; *list; list++) - free((void *) *list); + free(*list); free(group); } diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h index 83607f26c..0fcf405d3 100644 --- a/hw/xfree86/parser/xf86Parser.h +++ b/hw/xfree86/parser/xf86Parser.h @@ -299,7 +299,7 @@ typedef struct { typedef struct { struct xorg_list entry; - const char **values; + char **values; } xf86MatchGroup; typedef struct { From 14fb6cf92c009d726f0a6b6e8b89cc48f2dd50eb Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 30 Jan 2014 09:16:23 +1000 Subject: [PATCH 07/17] Revert "xfree86/common: handle string constants in xf86Xinput configuration" This reverts commit 22592855e90d23013ba7f9e945d567725cb44bf3. What warning was this supposed to fix? Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede --- hw/xfree86/common/xf86Xinput.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/common/xf86Xinput.c b/hw/xfree86/common/xf86Xinput.c index 3a0151374..f6f2b90dd 100644 --- a/hw/xfree86/common/xf86Xinput.c +++ b/hw/xfree86/common/xf86Xinput.c @@ -539,7 +539,7 @@ MatchAttrToken(const char *attr, struct xorg_list *patterns, * match. Each list entry is a separate Match line of the same type. */ xorg_list_for_each_entry(group, patterns, entry) { - const char *const *cur; + char *const *cur; Bool match = FALSE; for (cur = group->values; *cur; cur++) @@ -598,7 +598,7 @@ InputClassMatches(const XF86ConfInputClassPtr iclass, const InputInfoPtr idev, * See if any of the device's tags match any of the MatchTag tokens. */ if (!xorg_list_is_empty(&iclass->match_tag)) { - const char *const *tag; + char *const *tag; Bool match; if (!attrs->tags) From 87ca80a7196949597113225405f3e4ee03bbee13 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 24 Jan 2014 18:32:54 +1000 Subject: [PATCH 08/17] dix: prevent a driver from initializing or submitting buttons > MAX_BUTTONS The server internally relies on arrays with a MAX_BUTTONS maximum size (which is the max the core protocol can transport). Make sure a driver adheres to that. Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- dix/devices.c | 1 + dix/getevents.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/dix/devices.c b/dix/devices.c index a875f03cc..1c86d5242 100644 --- a/dix/devices.c +++ b/dix/devices.c @@ -1279,6 +1279,7 @@ InitButtonClassDeviceStruct(DeviceIntPtr dev, int numButtons, Atom *labels, BUG_RETURN_VAL(dev == NULL, FALSE); BUG_RETURN_VAL(dev->button != NULL, FALSE); + BUG_RETURN_VAL(numButtons >= MAX_BUTTONS, FALSE); butc = calloc(1, sizeof(ButtonClassRec)); if (!butc) diff --git a/dix/getevents.c b/dix/getevents.c index 646c723ea..ffa89fad2 100644 --- a/dix/getevents.c +++ b/dix/getevents.c @@ -1655,6 +1655,8 @@ GetPointerEvents(InternalEvent *events, DeviceIntPtr pDev, int type, } #endif + BUG_RETURN_VAL(buttons >= MAX_BUTTONS, 0); + /* refuse events from disabled devices */ if (!pDev->enabled) return 0; From 73926622b91fde01148727f26d6aad5e6827c1d2 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 24 Jan 2014 18:33:54 +1000 Subject: [PATCH 09/17] include: make the various button array lengths more obvious No functional changes, just making a better case for why MAP_LENGTH is 256. "But can't we remove MAP_LENGTH then?" I hear you say? "Why, yes. Go for it!" Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- include/input.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/input.h b/include/input.h index 6f047ee9c..93c45107d 100644 --- a/include/input.h +++ b/include/input.h @@ -95,8 +95,8 @@ SOFTWARE. #define NO_AXIS_LIMITS -1 -#define MAP_LENGTH 256 -#define DOWN_LENGTH 32 /* 256/8 => number of bytes to hold 256 bits */ +#define MAP_LENGTH MAX_BUTTONS +#define DOWN_LENGTH (MAX_BUTTONS/8) /* 256/8 => number of bytes to hold 256 bits */ #define NullGrab ((GrabPtr)NULL) #define PointerRootWin ((WindowPtr)PointerRoot) #define NoneWin ((WindowPtr)None) From 25d10464f440b8b34594b7c988a99a830ea39a29 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 24 Jan 2014 18:16:54 +1000 Subject: [PATCH 10/17] dix: fix button state check before changing a button mapping dev->button->down is a bitmask, not a normal array. Use the helper function to check, we technically allow the mapping to change after the physical button has been pressed (but not yet processed yet), so only check BUTTON_PROCESSED. From XSetPointerMapping(3): "If any of the buttons to be altered are logically in the down state, XSetPointerMapping returns MappingBusy, and the mapping is not changed." Reported-by: Ilja Van Sprundel Signed-off-by: Peter Hutterer Reviewed-by: Daniel Stone --- dix/inpututils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dix/inpututils.c b/dix/inpututils.c index a10a7c761..e5bcc31f7 100644 --- a/dix/inpututils.c +++ b/dix/inpututils.c @@ -60,7 +60,8 @@ check_butmap_change(DeviceIntPtr dev, CARD8 *map, int len, CARD32 *errval_out, } for (i = 0; i < len; i++) { - if (dev->button->map[i + 1] != map[i] && dev->button->down[i + 1]) + if (dev->button->map[i + 1] != map[i] && + button_is_down(dev, i + 1, BUTTON_PROCESSED)) return MappingBusy; } From 93bf9544712a39f10557533993d8826b2b67fc9a Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 5 Feb 2014 14:16:01 +1000 Subject: [PATCH 11/17] xfree86: device name and driver are not const char Allocated in one place, freed in another. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede Reviewed-by: Keith Packard --- hw/xfree86/common/xf86Xinput.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/xfree86/common/xf86Xinput.h b/hw/xfree86/common/xf86Xinput.h index f94261a01..b6d125128 100644 --- a/hw/xfree86/common/xf86Xinput.h +++ b/hw/xfree86/common/xf86Xinput.h @@ -82,8 +82,8 @@ typedef struct _InputDriverRec { typedef struct _InputInfoRec { struct _InputInfoRec *next; - const char *name; - const char *driver; + char *name; + char *driver; int flags; From 46ae9d67e4118fa79bef0f9119d20559dfd6b6c0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 5 Feb 2014 14:24:54 +1000 Subject: [PATCH 12/17] xfree86: un-constify inp_driver/inp_identifier The only place this isn't allocated is during Xorg -configure where we just statically assing "mouse"/"kbd" and the identifiers for it. Everywhere else it's strdup'd and then free'd already. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede Reviewed-by: Keith Packard --- hw/xfree86/common/xf86Configure.c | 8 ++++---- hw/xfree86/parser/xf86Parser.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 30dc5505c..5fc13997d 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -159,8 +159,8 @@ configureInputSection(void) parsePrologue(XF86ConfInputPtr, XF86ConfInputRec) - ptr->inp_identifier = "Keyboard0"; - ptr->inp_driver = "kbd"; + ptr->inp_identifier = strdup("Keyboard0"); + ptr->inp_driver = strdup("kbd"); ptr->list.next = NULL; /* Crude mechanism to auto-detect mouse (os dependent) */ @@ -175,8 +175,8 @@ configureInputSection(void) } mouse = calloc(1, sizeof(XF86ConfInputRec)); - mouse->inp_identifier = "Mouse0"; - mouse->inp_driver = "mouse"; + mouse->inp_identifier = strdup("Mouse0"); + mouse->inp_driver = strdup("mouse"); mouse->inp_option_lst = xf86addNewOption(mouse->inp_option_lst, strdup("Protocol"), strdup(DFLT_MOUSE_PROTO)); diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h index 0fcf405d3..2871edd4c 100644 --- a/hw/xfree86/parser/xf86Parser.h +++ b/hw/xfree86/parser/xf86Parser.h @@ -279,8 +279,8 @@ typedef struct { typedef struct { GenericListRec list; - const char *inp_identifier; - const char *inp_driver; + char *inp_identifier; + char *inp_driver; XF86OptionPtr inp_option_lst; char *inp_comment; } XF86ConfInputRec, *XF86ConfInputPtr; From f14d6647c0883d4e7e4de7645d7a18e4d301845e Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 5 Feb 2014 14:30:50 +1000 Subject: [PATCH 13/17] xfree86: unconstify another string Only Xorg -configure uses a hardcoded value here, so let's not change the rest of the server for that. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede Reviewed-by: Keith Packard --- hw/xfree86/common/xf86Configure.c | 4 ++-- hw/xfree86/parser/xf86Parser.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 5fc13997d..6aaf634a4 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -337,7 +337,7 @@ configureLayoutSection(void) iptr = malloc(sizeof(XF86ConfInputrefRec)); iptr->list.next = NULL; iptr->iref_option_lst = NULL; - iptr->iref_inputdev_str = "Mouse0"; + iptr->iref_inputdev_str = strdup("Mouse0"); iptr->iref_option_lst = xf86addNewOption(iptr->iref_option_lst, strdup("CorePointer"), NULL); @@ -351,7 +351,7 @@ configureLayoutSection(void) iptr = malloc(sizeof(XF86ConfInputrefRec)); iptr->list.next = NULL; iptr->iref_option_lst = NULL; - iptr->iref_inputdev_str = "Keyboard0"; + iptr->iref_inputdev_str = strdup("Keyboard0"); iptr->iref_option_lst = xf86addNewOption(iptr->iref_option_lst, strdup("CoreKeyboard"), NULL); diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h index 2871edd4c..d352d4b9b 100644 --- a/hw/xfree86/parser/xf86Parser.h +++ b/hw/xfree86/parser/xf86Parser.h @@ -288,7 +288,7 @@ typedef struct { typedef struct { GenericListRec list; XF86ConfInputPtr iref_inputdev; - const char *iref_inputdev_str; + char *iref_inputdev_str; XF86OptionPtr iref_option_lst; } XF86ConfInputrefRec, *XF86ConfInputrefPtr; From 72967d6c153b0d1109df23967e1a05c3c397a1e0 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 5 Feb 2014 14:32:23 +1000 Subject: [PATCH 14/17] xfree86: unconstify driver in the XF86ConfInputClassRec No const value is ever assigned to it, let's not pretend it's const. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede Reviewed-by: Keith Packard --- hw/xfree86/parser/xf86Parser.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xfree86/parser/xf86Parser.h b/hw/xfree86/parser/xf86Parser.h index d352d4b9b..8f855ac09 100644 --- a/hw/xfree86/parser/xf86Parser.h +++ b/hw/xfree86/parser/xf86Parser.h @@ -305,7 +305,7 @@ typedef struct { typedef struct { GenericListRec list; char *identifier; - const char *driver; + char *driver; struct xorg_list match_product; struct xorg_list match_vendor; struct xorg_list match_device; From c64130c13bd6914a998a8e8b808a6cedd18f9384 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 5 Feb 2014 15:10:27 +1000 Subject: [PATCH 15/17] dix: fix a -Wshadow warning dispatch.c: In function 'SetVendorString': dispatch.c:481:29: warning: declaration of 'string' shadows a global declaration [-Wshadow] SetVendorString(const char *string) ^ dispatch.c:135:21: warning: shadowed declaration is here [-Wshadow] typedef const char *string; Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede Reviewed-by: Keith Packard --- dix/dispatch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dix/dispatch.c b/dix/dispatch.c index 9a5658db0..4f830f7f4 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -478,9 +478,9 @@ SetVendorRelease(int release) } void -SetVendorString(const char *string) +SetVendorString(const char *vendor) { - VendorString = string; + VendorString = vendor; } Bool From 7b1b7fb3be47672454837a3f7be2d1440433ec27 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 5 Feb 2014 15:12:22 +1000 Subject: [PATCH 16/17] mi: fix printf warning about size_t format specifier mieq.c:290:26: warning: format '%u' expects argument of type 'unsigned int', but argument 2 has type 'size_t' [-Wformat=] pnprintf supports size_t since 5ea21560dd071ea4ab87430000d087fd5fe1f092 Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede Reviewed-by: Keith Packard --- mi/mieq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mi/mieq.c b/mi/mieq.c index bc7f94523..36aa21357 100644 --- a/mi/mieq.c +++ b/mi/mieq.c @@ -286,7 +286,7 @@ mieqEnqueue(DeviceIntPtr pDev, InternalEvent *e) else if (miEventQueue.dropped % QUEUE_DROP_BACKTRACE_FREQUENCY == 0 && miEventQueue.dropped / QUEUE_DROP_BACKTRACE_FREQUENCY <= QUEUE_DROP_BACKTRACE_MAX) { - ErrorFSigSafe("[mi] EQ overflow continuing. %u events have been " + ErrorFSigSafe("[mi] EQ overflow continuing. %zu events have been " "dropped.\n", miEventQueue.dropped); if (miEventQueue.dropped / QUEUE_DROP_BACKTRACE_FREQUENCY == QUEUE_DROP_BACKTRACE_MAX) { From 0b193b3ac94e078d9291d1b1dfd4814e5f2d9e34 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 6 Feb 2014 07:59:07 +1000 Subject: [PATCH 17/17] xfree86: use xnfstrdup in the Xorg -configure code Just for consistency, I'm pretty sure the code is generally not happy for malloc failures anyway. Signed-off-by: Peter Hutterer Reviewed-by: Hans de Goede Reviewed-by: Keith Packard --- hw/xfree86/common/xf86Configure.c | 42 +++++++++++++++---------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 6aaf634a4..967bfbc93 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -159,8 +159,8 @@ configureInputSection(void) parsePrologue(XF86ConfInputPtr, XF86ConfInputRec) - ptr->inp_identifier = strdup("Keyboard0"); - ptr->inp_driver = strdup("kbd"); + ptr->inp_identifier = xnfstrdup("Keyboard0"); + ptr->inp_driver = xnfstrdup("kbd"); ptr->list.next = NULL; /* Crude mechanism to auto-detect mouse (os dependent) */ @@ -175,17 +175,17 @@ configureInputSection(void) } mouse = calloc(1, sizeof(XF86ConfInputRec)); - mouse->inp_identifier = strdup("Mouse0"); - mouse->inp_driver = strdup("mouse"); + mouse->inp_identifier = xnfstrdup("Mouse0"); + mouse->inp_driver = xnfstrdup("mouse"); mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, strdup("Protocol"), - strdup(DFLT_MOUSE_PROTO)); + xf86addNewOption(mouse->inp_option_lst, xnfstrdup("Protocol"), + xnfstrdup(DFLT_MOUSE_PROTO)); mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, strdup("Device"), - strdup(DFLT_MOUSE_DEV)); + xf86addNewOption(mouse->inp_option_lst, xnfstrdup("Device"), + xnfstrdup(DFLT_MOUSE_DEV)); mouse->inp_option_lst = - xf86addNewOption(mouse->inp_option_lst, strdup("ZAxisMapping"), - strdup("4 5 6 7")); + xf86addNewOption(mouse->inp_option_lst, xnfstrdup("ZAxisMapping"), + xnfstrdup("4 5 6 7")); ptr = (XF86ConfInputPtr) xf86addListItem((glp) ptr, (glp) mouse); return ptr; } @@ -290,7 +290,7 @@ configureDeviceSection(int screennum) " ### : \"String\", : \" Hz/kHz/MHz\",\n" " ### : \"%\"\n" " ### [arg]: arg optional\n"; - ptr->dev_comment = strdup(descrip); + ptr->dev_comment = xnfstrdup(descrip); if (ptr->dev_comment) { for (p = DevToConfig[screennum].GDev.options; p->name != NULL; p++) { char *p_e; @@ -337,9 +337,9 @@ configureLayoutSection(void) iptr = malloc(sizeof(XF86ConfInputrefRec)); iptr->list.next = NULL; iptr->iref_option_lst = NULL; - iptr->iref_inputdev_str = strdup("Mouse0"); + iptr->iref_inputdev_str = xnfstrdup("Mouse0"); iptr->iref_option_lst = - xf86addNewOption(iptr->iref_option_lst, strdup("CorePointer"), + xf86addNewOption(iptr->iref_option_lst, xnfstrdup("CorePointer"), NULL); ptr->lay_input_lst = (XF86ConfInputrefPtr) xf86addListItem((glp) ptr->lay_input_lst, (glp) iptr); @@ -351,9 +351,9 @@ configureLayoutSection(void) iptr = malloc(sizeof(XF86ConfInputrefRec)); iptr->list.next = NULL; iptr->iref_option_lst = NULL; - iptr->iref_inputdev_str = strdup("Keyboard0"); + iptr->iref_inputdev_str = xnfstrdup("Keyboard0"); iptr->iref_option_lst = - xf86addNewOption(iptr->iref_option_lst, strdup("CoreKeyboard"), + xf86addNewOption(iptr->iref_option_lst, xnfstrdup("CoreKeyboard"), NULL); ptr->lay_input_lst = (XF86ConfInputrefPtr) xf86addListItem((glp) ptr->lay_input_lst, (glp) iptr); @@ -431,9 +431,9 @@ configureFilesSection(void) parsePrologue(XF86ConfFilesPtr, XF86ConfFilesRec) if (xf86ModulePath) - ptr->file_modulepath = strdup(xf86ModulePath); + ptr->file_modulepath = xnfstrdup(xf86ModulePath); if (defaultFontPath) - ptr->file_fontpath = strdup(defaultFontPath); + ptr->file_fontpath = xnfstrdup(defaultFontPath); return ptr; } @@ -446,8 +446,8 @@ configureMonitorSection(int screennum) XNFasprintf(&tmp, "Monitor%d", screennum); ptr->mon_identifier = tmp; - ptr->mon_vendor = strdup("Monitor Vendor"); - ptr->mon_modelname = strdup("Monitor Model"); + ptr->mon_vendor = xnfstrdup("Monitor Vendor"); + ptr->mon_modelname = xnfstrdup("Monitor Model"); return ptr; } @@ -491,7 +491,7 @@ configureDDCMonitorSection(int screennum) XNFasprintf(&tmp, "Monitor%d", screennum); ptr->mon_identifier = tmp; - ptr->mon_vendor = strdup(ConfiguredMonitor->vendor.name); + ptr->mon_vendor = xnfstrdup(ConfiguredMonitor->vendor.name); XNFasprintf(&ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id); /* features in centimetres, we want millimetres */ @@ -529,7 +529,7 @@ configureDDCMonitorSection(int screennum) if (ConfiguredMonitor->features.dpms) { ptr->mon_option_lst = - xf86addNewOption(ptr->mon_option_lst, strdup("DPMS"), NULL); + xf86addNewOption(ptr->mon_option_lst, xnfstrdup("DPMS"), NULL); } return ptr;