[PATCH synaptics 1/3] Constify priv->device
Daniel Kurtz
djkurtz at google.com
Mon Jan 2 20:03:58 PST 2012
On Tue, Jan 3, 2012 at 11:37 AM, Peter Hutterer <peter.hutterer at who-t.net>wrote:
> 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.
>
I believe this is the classic: "pointer to const void", versus "const
pointer to void".
* The typedef creates a "pointer to void", which you then constify in the
arg list ("const pointer to void").
* The non-typedef version is a "pointer to const void".
The 'typedef' creates an atomic type - it is not a macro that you can
prepend "const" to later to constify the type being pointed to.
You would need a new typedef, like this:
typedef const void * cpointer;
Happy New Year,
-Dan
>
> 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
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: http://lists.x.org/mailman/listinfo/xorg-devel
>
--
Daniel Kurtz | Software Engineer | djkurtz at google.com | 650.204.0722
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.x.org/archives/xorg-devel/attachments/20120103/6e16c42f/attachment-0001.html>
More information about the xorg-devel
mailing list