[PATCH 00/37] Warning fixes (post 1.15 proposed changes)

Thierry Reding thierry.reding at gmail.com
Mon Nov 18 03:11:18 PST 2013


On Sun, Nov 17, 2013 at 08:47:05PM +0000, Daniel Stone wrote:
> Hi,
> 
> On 17 November 2013 08:01, Keith Packard <keithp at keithp.com> wrote:
> > The only warning I removed from xorg-macros was -Wcast-qual as that
> > makes it impossible to free a const char * pointer. Casts exist to
> > work around limitations of the C type system, having it warn when
> > we're doing that is annoying.
> 
> Yeah, it's pretty ridiculous.  We ship this in libxkbcommon, which
> still seems to work:
> #define UNCONSTIFY(const_ptr)  ((void *) (uintptr_t) (const_ptr))

A lot of libraries that I've worked with have used const char * to
return strings which never should be freed (such as statically allocated
ones), and make use of this warning to catch incorrect usage of those.

There are quite a few locations where this manifests itself in the X
stack as well. The first one that comes to mind is the .driverName field
in struct _ScrnInfoRec. Most, if not all, drivers initialize that with a
static string, which causes gcc (and probably other compilers as well)
to complain because the const qualifier is discarded. However if the
warning is suppressed there's no way to automatically check that this
pointer isn't eventually passed to free().

We can obviously make sure that that never happens by careful code
review, but I don't see why we wouldn't want to have the compiler assist
with the task.

Of course to make proper use of that, quite a bit of code will need to
be changed first.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20131118/e76ae18f/attachment.pgp>


More information about the xorg-devel mailing list