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

Thierry Reding thierry.reding at gmail.com
Mon Nov 18 08:15:45 PST 2013


On Mon, Nov 18, 2013 at 07:42:07AM -0800, Keith Packard wrote:
> Thierry Reding <thierry.reding at gmail.com> writes:
> 
> > Of course to make proper use of that, quite a bit of code will need to
> > be changed first.
> 
> Having miles of compiler warning spam is not helpful though, so we need
> to tailor the warning set to those which are actually useful for a
> particular project. In this case, X uses the same data structures to
> hold both string constants and allocated memory. I can think of lots of
> fixes for this, but simply sticking a cast in the free parameter seems
> the least invasive to me, while preserving most of the checks. Having to
> hack around the -Wcast-qual check with an intermediate cast to
> (uintptr_t) seems silly.

I wasn't implying that we hack around anything. What I suggested was to
fix it properly by not using const for pointers to dynamically allocated
memory which is meant to be freed at some point. Conversely, non-const
pointers will then imply memory that's been dynamically allocated and
therefore can (and should) be freed.

If you absolutely must be able to use either statically or dynamically
allocated strings in the same data structure, why not just go and
strdup() string constants so that you can treat the structure in the
same way subsequently?

Using the same data structure to hold both constant (static) strings and
dynamically allocated ones seems bound to lead to issues at some point.
Either you free the memory (in which case you might be freeing a static
string and cause a crash) or you don't, in which case you might cause a
memory leak.

That is, unless you have other means to determine that a particular
instance of a structure is guaranteed to contain a static or dynamic
string.

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/b5bb1a47/attachment.pgp>


More information about the xorg-devel mailing list