Commit 2422a514 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Fixed zero-size allocation

parent eae7c1c8
Loading
Loading
Loading
Loading
+10 −5
Original line number Diff line number Diff line
@@ -175,12 +175,17 @@ setSize( const Index size )
   if( this->size == size && allocationPointer && ! referenceCounter )
      return;
   this->releaseData();

   // Allocating zero bytes is useless. Moreover, the allocators don't behave the same way:
   // "operator new" returns some non-zero address, the latter returns a null pointer.
   if( size > 0 ) {
      Algorithms::ArrayOperations< Device >::allocateMemory( this->allocationPointer, size );
      this->data = this->allocationPointer;
      this->size = size;
      TNL_ASSERT( this->allocationPointer,
                  std::cerr << "This should never happen - allocator did not throw on an error." << std::endl; );
   }
}

template< typename Element,
          typename Device,