On Sun, Nov 17, 2013 at 08:47:05PM +0000, Daniel Stone wrote: > Hi, > > On 17 November 2013 08:01, Keith Packard <[email protected]> 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
pgpyz60Y5pJOw.pgp
Description: PGP signature
_______________________________________________ [email protected]: X.Org development Archives: http://lists.x.org/archives/xorg-devel Info: http://lists.x.org/mailman/listinfo/xorg-devel
