[vtk-developers] vtkDataArrayTemplate.cxx writes out of bounds when malloc fails

Burlen Loring burlen.loring at kitware.com
Sun Jun 22 20:04:26 EDT 2008

Hi all,

Thanks for all of the feedback. I think we have an acceptable solution 
at hand. We can continue to use malloc/realloc/free and when 
malloc/realloc fails, handle as follows:

newArray = static_cast<T*>(malloc(newSize*sizeof(T)));
  vtkErrorMacro("Unable to allocate " << newSize
                << " elements of size " << sizeof(T)
                << " bytes. ");
  #if !defined NDEBUG
  // We're debugging, crash here preserving the stack
  #elif !defined VTK_DONT_THROW_BAD_ALLOC
  // We can throw something that has universal meaning
  throw vtkstd::bad_alloc();
  // We indicate that malloc failed by return
  return 0;

I am attaching the patch for any who wishes to review in more detail. Is 
there any objection to this approach?

Thanks in advance.

Burlen Loring
Kitware, Inc.
R&D Engineer
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-371-3971 x137

-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtkDataArrayTemplate.txx.patch
Type: text/x-diff
Size: 10706 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20080622/ccb8f664/attachment-0001.patch>

More information about the vtk-developers mailing list