wxWidgets and memory allocation failures.

Jurko Gospodnetić jurko_for_boost at mail.inet.hr
Mon Apr 9 17:40:30 PDT 2007


  Hi.

>  I'm not sure how is this supposed to happen. Dereferencing a NULL pointer
> seems much more likely.

   Here are some more cases I ran into while looking through the 
wxWidgets sources. Again, I'm using the 2.8.3 sources.

   In the common/string.cpp module wxStringBase::CopyBeforeWrite() 
failures sometimes do not get handled in release mode:

   * wxStringBase::begin() and wxStringBase::end() may return non-const 
iterators pointing to shared string data and so allow changing all 
shared string instances at once instead of just the given one without 
caller getting any change to detect this.

   * wxStringBase::insert(size_t nPos, const wxChar *sz, size_t n) 
ignores out-of-memory failures in release mode and may trash memory 
outside the allocated buffer.

   Hope this helps...


   I have also noticed that the C++ new operator is used a lot 
throughout the code, but have not seen where its std::bad_alloc 
exception throwing gets disables. I guess one way you could do it by 
defining a global operator new but I have not seen one of those except 
for debugging purposes. Another way would be to play around with C++ 
run-time library linking order and link first with a version of the 
run-time library whose operator new implementation does not throw an 
exception, but I have not been able to find this either (I'm using MSVC 
7.1).

   Best regards,
     Jurko Gospodnetić





More information about the wx-users mailing list