[PATCH 1/7] Fix a couple of compiler warnings

Dan Nicholson dbn.lists at gmail.com
Tue May 18 13:58:43 PDT 2010


2010/5/14 Keith Packard <keithp at keithp.com>:
> On Thu, 13 May 2010 09:49:45 -0400, Kristian Høgsberg <krh at bitplanet.net> wrote:
>>
>> This works for me and seems like a better way to fix those warnings:
>>
>> diff --git a/include/input.h b/include/input.h
>> index 63f981e..eba4292 100644
>> --- a/include/input.h
>> +++ b/include/input.h
>> @@ -212,10 +212,10 @@ typedef struct _InputOption {
>>  } InputOption;
>>
>>  typedef struct _InputAttributes {
>> -    char                *product;
>> -    char                *vendor;
>> -    char                *device;
>> -    char                **tags; /* null-terminated */
>> +    const char         *product;
>> +    const char         *vendor;
>> +    const char         *device;
>> +    const char        **tags; /* null-terminated */
>>      uint32_t            flags;
>>  } InputAttributes;
>
> I had to add some casts while freeing to get rid of the warnings there
> too:
>
> From 398b7b0922732fbaa0418059e93efeed57070167 Mon Sep 17 00:00:00 2001
> From: Keith Packard <keithp at keithp.com>
> Date: Fri, 14 May 2010 17:39:18 -0700
> Subject: [PATCH] Fix a couple of compiler warnings
>
> Signed-off-by: Keith Packard <keithp at keithp.com>
> ---
>  config/udev.c   |    8 ++++----
>  include/input.h |    8 ++++----
>  2 files changed, 8 insertions(+), 8 deletions(-)

Please also fix config/hal. Or see the other thread.

http://lists.freedesktop.org/archives/xorg-devel/2010-May/008239.html

Either way, let's get something in. I keep having to rebase patches on
these changes.

> diff --git a/config/udev.c b/config/udev.c
> index 5e8d8da..c579ee2 100644
> --- a/config/udev.c
> +++ b/config/udev.c
> @@ -87,7 +87,7 @@ device_added(struct udev_device *udev_device)
>     add_option(&options, "path", path);
>     add_option(&options, "device", path);
>     attrs.device = path;
> -    attrs.tags = xstrtokenize(udev_device_get_property_value(udev_device, "ID_INPUT.tags"), ",");
> +    attrs.tags = (const char *const *) xstrtokenize(udev_device_get_property_value(udev_device, "ID_INPUT.tags"), ",");
>
>     config_info = Xprintf("udev:%s", syspath);
>     if (!config_info)
> @@ -155,12 +155,12 @@ device_added(struct udev_device *udev_device)
>     }
>
>     if (attrs.tags) {
> -        char **tag = attrs.tags;
> +        const char *const *tag = attrs.tags;
>         while (*tag) {
> -            free(*tag);
> +            free((void *) *tag);
>             tag++;
>         }
> -        free(attrs.tags);
> +        free((void *) attrs.tags);

There's a lot less casting if you use a temporary char ** variable and
then set attr.tags equal to it.

--
Dan


More information about the xorg-devel mailing list