Fwd: Re: deleting null pointer arrays (was: Re: extragear/network/ktorrent)
Michael Pyne
mpyne at purinchu.net
Fri Jan 16 00:49:25 GMT 2009
On Thursday 15 January 2009, Dominik Haumann wrote:
> Hi,
>
> according to [1] this change is wrong:
> >> BitSet & BitSet::operator = (const BitSet & bs)
> >> {
> >> - if (data)
> >> - delete [] data;
> >> + delete [] data
>
> Still, it seems to be unclear whether that's sill an issue.
> Does anyone have an idea?
>
> Dominik
>
> [1]
> http://techbase.kde.org/Development/Tutorials/Common_Programming_Mistakes#N
>ULL_pointer_issues
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.
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.
Whether or not we want to work around it is a different story but delete[] on
a null pointer is perfectly valid C++.
Regards,
- Michael Pyne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090115/87adfa00/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20090115/87adfa00/attachment.sig>
More information about the kde-core-devel
mailing list