Skip to content
  • Ole John Aske's avatar
    e4ce828d
    Fix for bug#13945264 · e4ce828d
    Ole John Aske authored
    VECTOR TEMPLATE HAS NO SAFE WAY TO SIGNAL 'OUT OF MEMORY' ERRORS
    
    Recommit fixing comments from Magnus B.
    
    The Vector template class does internal memory allocation in 
    several methods which are 'void'.
    As our code is compiled without exceptions, there are no 
    safe way to return an 'out of memory' error from these methods.
    
    The questionable methods are:
      1) Vector<T>::Vector(unsigned sz = 10)  (Constructor)
      2) Vector<T>::Vector(const Vector& src) (Copy constructor)
      3) Vector<T>& Vector<T>::operator=(const Vector<T>& obj)
      4) void Vector<T>::push(const T & t, unsigned pos)
      5) MutexVector<T>::MutexVector(unsigned sz = 10)
    
    For the C'tors taking a size_t argument the implementation did not
    correctly handle the case 'size==0'. We wan't to fix this such that 
    
    - The C'tors should correctly handle 'size==0' such that 
      no initial memory allocation is attempted in these cases,
      Thus no 'out of memory' allocation can be produced.
    
    - Introduce a new 'int ::expand(unsigned sz)' which do an initial
      alloc of the Vector to the specified size.
    
    - Add comments which encourage the user to replace 'Vector(size>0)'
      constructors with 'Vector(0) + ::expand(n)' constructions.
    
    - Add comments which encourage the user to replace copy constructors
      and assignment operators with empty Vector(0) C'tors and then use
      'int Vector::assign()' to fill in the contents.
    
    - Changed Vector::push() to return an 'int' used to signal failure.
    
    Furthermore, no (deep-) copy constructor or assignment operator was
    defined for MutexVector such that an incorrect default C'tor would
    be called. Copy-c'tor and assign operator has now been disallowed.
    
    NOTE: This is part 1 of the fix. There will be a part 2 which fix
    up Vector usage in NdbQueryBuilder and NdbQueryOperator which
    has been reported as a problem in:
    
    https://support.us.oracle.com/oip/faces/secure/ml3/sr/SRDetail.jspx?SRNumber=3-5513205231
    
    
    ... As these problem has not been reproduced locally we are not sure this will
    fix the problem though. However it should improve code quality.
    ******
    Part 2 fix for Bug#13945264: VECTOR TEMPLATE HAS NO SAFE WAY TO SIGNAL 'OUT OF MEMORY' ERRORS
    
    Changes usage of Vector in the SPJ API such that memory alloc failured
    from Vector is now detected by using Vector methods returning an 'int' != 0
    instead of checking 'errno == ENOMEM' 
    e4ce828d
    Fix for bug#13945264
    Ole John Aske authored
    VECTOR TEMPLATE HAS NO SAFE WAY TO SIGNAL 'OUT OF MEMORY' ERRORS
    
    Recommit fixing comments from Magnus B.
    
    The Vector template class does internal memory allocation in 
    several methods which are 'void'.
    As our code is compiled without exceptions, there are no 
    safe way to return an 'out of memory' error from these methods.
    
    The questionable methods are:
      1) Vector<T>::Vector(unsigned sz = 10)  (Constructor)
      2) Vector<T>::Vector(const Vector& src) (Copy constructor)
      3) Vector<T>& Vector<T>::operator=(const Vector<T>& obj)
      4) void Vector<T>::push(const T & t, unsigned pos)
      5) MutexVector<T>::MutexVector(unsigned sz = 10)
    
    For the C'tors taking a size_t argument the implementation did not
    correctly handle the case 'size==0'. We wan't to fix this such that 
    
    - The C'tors should correctly handle 'size==0' such that 
      no initial memory allocation is attempted in these cases,
      Thus no 'out of memory' allocation can be produced.
    
    - Introduce a new 'int ::expand(unsigned sz)' which do an initial
      alloc of the Vector to the specified size.
    
    - Add comments which encourage the user to replace 'Vector(size>0)'
      constructors with 'Vector(0) + ::expand(n)' constructions.
    
    - Add comments which encourage the user to replace copy constructors
      and assignment operators with empty Vector(0) C'tors and then use
      'int Vector::assign()' to fill in the contents.
    
    - Changed Vector::push() to return an 'int' used to signal failure.
    
    Furthermore, no (deep-) copy constructor or assignment operator was
    defined for MutexVector such that an incorrect default C'tor would
    be called. Copy-c'tor and assign operator has now been disallowed.
    
    NOTE: This is part 1 of the fix. There will be a part 2 which fix
    up Vector usage in NdbQueryBuilder and NdbQueryOperator which
    has been reported as a problem in:
    
    https://support.us.oracle.com/oip/faces/secure/ml3/sr/SRDetail.jspx?SRNumber=3-5513205231
    
    
    ... As these problem has not been reproduced locally we are not sure this will
    fix the problem though. However it should improve code quality.
    ******
    Part 2 fix for Bug#13945264: VECTOR TEMPLATE HAS NO SAFE WAY TO SIGNAL 'OUT OF MEMORY' ERRORS
    
    Changes usage of Vector in the SPJ API such that memory alloc failured
    from Vector is now detected by using Vector methods returning an 'int' != 0
    instead of checking 'errno == ENOMEM' 
Loading