[PATCH synaptics 1/3] Constify priv->device

Chase Douglas chase.douglas at canonical.com
Mon Jan 2 19:08:09 PST 2012


On 01/02/2012 05:19 PM, Peter Hutterer wrote:
> synaptics.c: In function 'SynapticsPreInit':
> synaptics.c:731:18: warning: assignment discards 'const' qualifier from
> pointer target type [enabled by default]
> 
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
>  src/properties.c   |    2 +-
>  src/synapticsstr.h |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/src/properties.c b/src/properties.c
> index f15a6fb..2affc17 100644
> --- a/src/properties.c
> +++ b/src/properties.c
> @@ -315,7 +315,7 @@ InitDeviceProperties(InputInfoPtr pInfo)
>          prop_device_node = MakeAtom(XI_PROP_DEVICE_NODE, strlen(XI_PROP_DEVICE_NODE), TRUE);
>          XIChangeDeviceProperty(pInfo->dev, prop_device_node, XA_STRING, 8,
>                                 PropModeReplace, strlen(priv->device),
> -                               priv->device, FALSE);
> +                               (const pointer)priv->device, FALSE);

This seems like a recipe for trouble. We're relying on an assumption of
how XIChangeDeviceProperty works. Either we should change the signature
of the library call, or we should use strcpy().

Even if we are 100% sure that XIChangeDeviceProperty will never modify
the string, it's just bad programming.

>          XISetDevicePropertyDeletable(pInfo->dev, prop_device_node, FALSE);
>      }
>  
> diff --git a/src/synapticsstr.h b/src/synapticsstr.h
> index 1ec8246..d74ebcd 100644
> --- a/src/synapticsstr.h
> +++ b/src/synapticsstr.h
> @@ -185,7 +185,7 @@ typedef struct _SynapticsPrivateRec
>  
>      struct SynapticsHwState hwState;
>  
> -    char *device;			/* device node */
> +    const char *device;			/* device node */

This looks good either way though.

-- Chase


More information about the xorg-devel mailing list