Changeset 127:c83307692316 in rrlib_rtti


Ignore:
Timestamp:
05.02.2020 09:06:13 (3 weeks ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
17.03
Children:
128:9b9df7f7fec1, 129:baeb0874a6d3
Phase:
public
Message:

Adds basic size check assertion to tTypedPointer::GetUnchecked method (there are no use cases for returning pointers to objects in invalid memory) and relaxes type check assertion in tTypedPointer::DeepCopyFrom to support several levels of underlying types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tTypedPointer.h

    r104 r127  
    161161 
    162162  /*! 
    163    * \return Wrapped object (no type checks via assertions are performed) 
     163   * \param check_exact_size Check that sizeof(T) matches size of wrapped object? (otherwise T may be smaller than wrapped object) 
     164   * \return Wrapped object (no check for exact type is performed) 
    164165   */ 
    165166  template <typename T> 
    166   inline const T* GetUnchecked() const 
    167   { 
     167  inline const T* GetUnchecked(bool check_exact_size = true) const 
     168  { 
     169    assert(sizeof(T) == type.GetSize() || ((!check_exact_size) && sizeof(T) <= type.GetSize())); 
    168170    return static_cast<const T*>(data); 
    169171  } 
     
    299301  inline void DeepCopyFrom(const tTypedConstPointer& source) const 
    300302  { 
    301     assert((source.GetType().GetUnderlyingType() == this->GetType().GetUnderlyingType()) && this->GetRawDataPointer() && source.GetRawDataPointer() && "Types must match and pointers must not be null"); 
     303    assert((source.GetType().GetSize() == this->GetType().GetSize()) && this->GetRawDataPointer() && source.GetRawDataPointer() && "Types must match and pointers must not be null"); 
    302304    if (source.GetRawDataPointer() != this->GetRawDataPointer()) 
    303305    { 
     
    414416 
    415417  /*! 
    416    * \return Wrapped object (no type checks via assertions are performed) 
     418   * \param check_exact_size Check that sizeof(T) matches size of wrapped object? (otherwise T may be smaller than wrapped object) 
     419   * \return Wrapped object (no check for exact type is performed) 
    417420   */ 
    418421  template <typename T> 
    419   inline T* GetUnchecked() const 
    420   { 
     422  inline T* GetUnchecked(bool check_exact_size = true) const 
     423  { 
     424    assert(sizeof(T) == type.GetSize() || ((!check_exact_size) && sizeof(T) <= type.GetSize())); 
    421425    return static_cast<T*>(data); 
    422426  } 
Note: See TracChangeset for help on using the changeset viewer.