Fwd: Re: deleting null pointer arrays (was: Re: extragear/network/ktorrent)

Adriaan de Groot groot at kde.org
Fri Jan 16 03:51:41 GMT 2009


As one of the dudes using the Sun C compiler the most on KDE code (and 
incidentally defining which versions are considered suitable for use), I'll 
chime in here.

On Friday 16 January 2009 01:49:25 Michael Pyne wrote:
> On Thursday 15 January 2009, Dominik Haumann wrote:
> > according to [1] this change is wrong:
> > >>         BitSet & BitSet::operator = (const BitSet & bs)
> > >>         {
> > >> -               if (data)
> > >> -                       delete [] data;
> > >> +               delete [] data
>
> The way delete [] works is that the size of the array is embedded somewhere
> in the array to be deleted (handled by the corresponding new[]).  delete[]
> uses this information to free the array appropriately.
>
> Apparently the "recent Solaris compiler" does not check for 0 before trying
> to find the hidden array length.

Might be. I'd have to know more from the OP about what version exactly that 
recent compiler is; Ceres (StudioExpress) is considered experimental; Mars 
124864-03 is slightly too old (but is what I'm using on my own laptop) and -08 
is approved.


> Section 5.3.5 of the C++ standard seems to define what happens when delete
> is called, and says that delete doing nothing for null pointers applies for
> both delete and delete[].  So the Solaris compiler has a bug.

I'd call it that as well. I tried to reproduce the problem with some simple 
twiddling, but could not. My test app did crash once, but I couldn't reproduce 
it later (note to self: even for random dicking around, start a SCM repo).

> Whether or not we want to work around it is a different story but delete[]
> on a null pointer is perfectly valid C++.

I'd say no. If it's a workaround that uglifies things, it should be in the 
KDE4-Solaris patch repositories. We want to keep the KDE upstream source code 
as clean and correct as possible and this kind of hack should be elsewhere.

[ade]




More information about the kde-core-devel mailing list