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

Peter Hutterer peter.hutterer at who-t.net
Mon Jan 2 19:37:13 PST 2012


On Mon, Jan 02, 2012 at 07:08:09PM -0800, Chase Douglas wrote:
> 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.

XIChangeDeviceProperty takes a const pointer argument, this should work
without the cast, except gcc did not like it.

properties.c:318:32: warning: passing argument 7 of 'XIChangeDeviceProperty'
discards 'const' qualifier from pointer target type [enabled by default]
/opt/xorg/include/xorg/exevents.h:88:51: note: expected 'pointer' but
argument is of type 'const char *'

if you knock up a 5-line test program, it appears that gcc has issues with
the typedef. the code below emits a warning, but the warning goes away when
bar changes to void bar(const void* a).

    typedef void* pointer;

    void bar(const pointer a)
    {
        printf("%lx\n", a);
    }

    int main (int argc, char **argv)
    {
        const char *foo;
        bar(foo);
        return 0;
    }

not sure why gcc complains here.

Cheers,
  Peter
> 
> >          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