input: un-constify InputAttributes
Introduced in fecc7eb1cf
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 <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
2fc38d1e29
commit
ce3df579e3
|
@ -242,16 +242,16 @@ device_added(struct udev_device *udev_device)
|
||||||
free(config_info);
|
free(config_info);
|
||||||
input_option_free_list(&input_options);
|
input_option_free_list(&input_options);
|
||||||
|
|
||||||
free((void *) attrs.usb_id);
|
free(attrs.usb_id);
|
||||||
free((void *) attrs.pnp_id);
|
free(attrs.pnp_id);
|
||||||
free((void *) attrs.product);
|
free(attrs.product);
|
||||||
free((void *) attrs.device);
|
free(attrs.device);
|
||||||
free((void *) attrs.vendor);
|
free(attrs.vendor);
|
||||||
if (attrs.tags) {
|
if (attrs.tags) {
|
||||||
const char **tag = attrs.tags;
|
char **tag = attrs.tags;
|
||||||
|
|
||||||
while (*tag) {
|
while (*tag) {
|
||||||
free((void *) *tag);
|
free(*tag);
|
||||||
tag++;
|
tag++;
|
||||||
}
|
}
|
||||||
free(attrs.tags);
|
free(attrs.tags);
|
||||||
|
|
|
@ -351,7 +351,7 @@ DuplicateInputAttributes(InputAttributes * attrs)
|
||||||
{
|
{
|
||||||
InputAttributes *new_attr;
|
InputAttributes *new_attr;
|
||||||
int ntags = 0;
|
int ntags = 0;
|
||||||
const char **tags, **new_tags;
|
char **tags, **new_tags;
|
||||||
|
|
||||||
if (!attrs)
|
if (!attrs)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -403,20 +403,20 @@ DuplicateInputAttributes(InputAttributes * attrs)
|
||||||
void
|
void
|
||||||
FreeInputAttributes(InputAttributes * attrs)
|
FreeInputAttributes(InputAttributes * attrs)
|
||||||
{
|
{
|
||||||
const char **tags;
|
char **tags;
|
||||||
|
|
||||||
if (!attrs)
|
if (!attrs)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
free((void *) attrs->product);
|
free(attrs->product);
|
||||||
free((void *) attrs->vendor);
|
free(attrs->vendor);
|
||||||
free((void *) attrs->device);
|
free(attrs->device);
|
||||||
free((void *) attrs->pnp_id);
|
free(attrs->pnp_id);
|
||||||
free((void *) attrs->usb_id);
|
free(attrs->usb_id);
|
||||||
|
|
||||||
if ((tags = attrs->tags))
|
if ((tags = attrs->tags))
|
||||||
while (*tags)
|
while (*tags)
|
||||||
free((void *) *tags++);
|
free(*tags++);
|
||||||
|
|
||||||
free(attrs->tags);
|
free(attrs->tags);
|
||||||
free(attrs);
|
free(attrs);
|
||||||
|
|
|
@ -221,12 +221,12 @@ typedef struct _InputOption InputOption;
|
||||||
typedef struct _XI2Mask XI2Mask;
|
typedef struct _XI2Mask XI2Mask;
|
||||||
|
|
||||||
typedef struct _InputAttributes {
|
typedef struct _InputAttributes {
|
||||||
const char *product;
|
char *product;
|
||||||
const char *vendor;
|
char *vendor;
|
||||||
const char *device;
|
char *device;
|
||||||
const char *pnp_id;
|
char *pnp_id;
|
||||||
const char *usb_id;
|
char *usb_id;
|
||||||
const char **tags; /* null-terminated */
|
char **tags; /* null-terminated */
|
||||||
uint32_t flags;
|
uint32_t flags;
|
||||||
} InputAttributes;
|
} InputAttributes;
|
||||||
|
|
||||||
|
|
56
test/input.c
56
test/input.c
|
@ -1101,7 +1101,7 @@ xi_unregister_handlers(void)
|
||||||
static void
|
static void
|
||||||
cmp_attr_fields(InputAttributes * attr1, InputAttributes * attr2)
|
cmp_attr_fields(InputAttributes * attr1, InputAttributes * attr2)
|
||||||
{
|
{
|
||||||
const char **tags1, **tags2;
|
char **tags1, **tags2;
|
||||||
|
|
||||||
assert(attr1 && attr2);
|
assert(attr1 && attr2);
|
||||||
assert(attr1 != attr2);
|
assert(attr1 != attr2);
|
||||||
|
@ -1180,50 +1180,54 @@ cmp_attr_fields(InputAttributes * attr1, InputAttributes * attr2)
|
||||||
static void
|
static void
|
||||||
dix_input_attributes(void)
|
dix_input_attributes(void)
|
||||||
{
|
{
|
||||||
InputAttributes orig = { 0 };
|
InputAttributes *orig;
|
||||||
InputAttributes *new;
|
InputAttributes *new;
|
||||||
const char *tags[4] = { "tag1", "tag2", "tag2", NULL };
|
|
||||||
|
|
||||||
new = DuplicateInputAttributes(NULL);
|
new = DuplicateInputAttributes(NULL);
|
||||||
assert(!new);
|
assert(!new);
|
||||||
|
|
||||||
new = DuplicateInputAttributes(&orig);
|
orig = calloc(1, sizeof(InputAttributes));
|
||||||
assert(memcmp(&orig, new, sizeof(InputAttributes)) == 0);
|
assert(orig);
|
||||||
|
|
||||||
orig.product = "product name";
|
new = DuplicateInputAttributes(orig);
|
||||||
new = DuplicateInputAttributes(&orig);
|
assert(memcmp(orig, new, sizeof(InputAttributes)) == 0);
|
||||||
cmp_attr_fields(&orig, new);
|
|
||||||
|
orig->product = xnfstrdup("product name");
|
||||||
|
new = DuplicateInputAttributes(orig);
|
||||||
|
cmp_attr_fields(orig, new);
|
||||||
FreeInputAttributes(new);
|
FreeInputAttributes(new);
|
||||||
|
|
||||||
orig.vendor = "vendor name";
|
orig->vendor = xnfstrdup("vendor name");
|
||||||
new = DuplicateInputAttributes(&orig);
|
new = DuplicateInputAttributes(orig);
|
||||||
cmp_attr_fields(&orig, new);
|
cmp_attr_fields(orig, new);
|
||||||
FreeInputAttributes(new);
|
FreeInputAttributes(new);
|
||||||
|
|
||||||
orig.device = "device path";
|
orig->device = xnfstrdup("device path");
|
||||||
new = DuplicateInputAttributes(&orig);
|
new = DuplicateInputAttributes(orig);
|
||||||
cmp_attr_fields(&orig, new);
|
cmp_attr_fields(orig, new);
|
||||||
FreeInputAttributes(new);
|
FreeInputAttributes(new);
|
||||||
|
|
||||||
orig.pnp_id = "PnPID";
|
orig->pnp_id = xnfstrdup("PnPID");
|
||||||
new = DuplicateInputAttributes(&orig);
|
new = DuplicateInputAttributes(orig);
|
||||||
cmp_attr_fields(&orig, new);
|
cmp_attr_fields(orig, new);
|
||||||
FreeInputAttributes(new);
|
FreeInputAttributes(new);
|
||||||
|
|
||||||
orig.usb_id = "USBID";
|
orig->usb_id = xnfstrdup("USBID");
|
||||||
new = DuplicateInputAttributes(&orig);
|
new = DuplicateInputAttributes(orig);
|
||||||
cmp_attr_fields(&orig, new);
|
cmp_attr_fields(orig, new);
|
||||||
FreeInputAttributes(new);
|
FreeInputAttributes(new);
|
||||||
|
|
||||||
orig.flags = 0xF0;
|
orig->flags = 0xF0;
|
||||||
new = DuplicateInputAttributes(&orig);
|
new = DuplicateInputAttributes(orig);
|
||||||
cmp_attr_fields(&orig, new);
|
cmp_attr_fields(orig, new);
|
||||||
FreeInputAttributes(new);
|
FreeInputAttributes(new);
|
||||||
|
|
||||||
orig.tags = tags;
|
orig->tags = xstrtokenize("tag1 tag2 tag3", " ");
|
||||||
new = DuplicateInputAttributes(&orig);
|
new = DuplicateInputAttributes(orig);
|
||||||
cmp_attr_fields(&orig, new);
|
cmp_attr_fields(orig, new);
|
||||||
FreeInputAttributes(new);
|
FreeInputAttributes(new);
|
||||||
|
|
||||||
|
FreeInputAttributes(orig);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue