Print

Print


Indeed the null pointer test before delete was only needed in very early 
  g++ compilers (before egcs). Now there is not a single compiler that 
needs this check anymore. The standard explicitly allows passing 0 
pointers to delete.

Cheers, Fons.


Alvise Dorigo wrote:
> 
> Hi Jacek, the SafeDelete is a "legacy" from ROOT. When the ROOT
> project started the C++ STL was not mature (e.g. string didn't
> exist), and probably also the language was not mature (probably the
> ANSI C++ wasn't out yet) and that could mean that they observed SEGV
> when trying to delete a null pointer (I do not think the had fun to
> do an extra check in the code).
> 
> We used SafeDelete (that checks for null-ness) just to be as
> compliant as possible with the ROOT  environment (for example using
> Int_t, Double_t etc. instead of int, double... that also guarantee
> portability).
> 
> Please feel free to modify the code (I hope Fabrizio agree with me),
> but also my experience suggests that every "micro-"change in the code
> should followed by a test of the code itself.
> 
> thanks
> 
> Alvise
> 
> Jacek Becla wrote:
> 
>> Hi Gregory
>> 
>> Not really. C++ guarantees that operator delete checks its argument
>>  for null-ness. If the argument is 0, the delete expression has no
>>  effect. In other words, deleting a null pointer is a safe (yet 
>> useless) operation. There is no need to check the pointer for 
>> null-ness before passing it to delete.
>> 
>> Jacek
>> 
>> 
>> 
>> 
>> Gregory J. Sharp wrote:
>> 
>>> Folks,
>>> 
>>> The following change might also be a suitable form of defensive 
>>> programming:
>>> 
>>> in XrdXr/XrdXrClientWorker.cc in the destructor, it would be 
>>> comforting to change:
>>> 
>>> delete xrootd;  xrootd  = 0; delete errInfo; errInfo = 0; to if
>>> (xrootd) { delete xrootd;  xrootd  = 0; } if (errInfo) { delete
>>> errInfo; errInfo = 0; }
>>> 
>>> and, totally free of charge, the trailing ; on the following line
>>> can go away.
>>> 
>>> -- Gregory J. Sharp                   email:
>>> [log in to unmask] Wilson Synchrotron Laboratory
>>> url: http://www.lepp.cornell.edu/~gregor Dryden Rd
>>> ph:  +1 607 255 4882 Ithaca, NY 14853                   fax: +1
>>> 607 255 8062
>>> 
> 

-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: [log in to unmask]              Phone: +41 22 7679248
WWW:    http://www.rademakers.org/fons/      Fax:   +41 22 7679480