Security Scol plugin
Public Types | Public Member Functions | Static Public Attributes | Static Protected Member Functions | List of all members
AllocatorBase< T > Class Template Reference

Base class for all allocators used by SecBlock. More...

#include <secblock.h>

Inheritance diagram for AllocatorBase< T >:
AllocatorWithCleanup< word64, true > AllocatorWithCleanup< word32, true > AllocatorWithCleanup< byte > AllocatorWithCleanup< byte, true > AllocatorWithCleanup< word32 > AllocatorWithCleanup< word16 > AllocatorWithCleanup< Deflator::EncodedMatch > AllocatorWithCleanup< HuffmanEncoder::Code > AllocatorWithCleanup< word, true > AllocatorWithCleanup< word > AllocatorWithCleanup< RC5_WORD > AllocatorWithCleanup< RC6_WORD > AllocatorWithCleanup< word64 > AllocatorWithCleanup< W, true > FixedSizeAllocatorWithCleanup< T, S, NullAllocator< T >, true > FixedSizeAllocatorWithCleanup< word32, S > FixedSizeAllocatorWithCleanup< word32, S, NullAllocator< word32 >, T_Align16 > FixedSizeAllocatorWithCleanup< word64, S > FixedSizeAllocatorWithCleanup< word64, S, NullAllocator< word64 >, T_Align16 > FixedSizeAllocatorWithCleanup< T, S, AllocatorWithCleanup< T > > FixedSizeAllocatorWithCleanup< byte, S > FixedSizeAllocatorWithCleanup< word32, S, NullAllocator< word32 >, true > FixedSizeAllocatorWithCleanup< byte, S, NullAllocator< byte >, T_Align16 > FixedSizeAllocatorWithCleanup< word16, S > FixedSizeAllocatorWithCleanup< unsigned int, S > FixedSizeAllocatorWithCleanup< Word, S > FixedSizeAllocatorWithCleanup< T_HashWordType, S > FixedSizeAllocatorWithCleanup< T_HashWordType, S, NullAllocator< T_HashWordType >, T_Align16 > FixedSizeAllocatorWithCleanup< byte, S, NullAllocator< byte >, true > AllocatorWithCleanup< T, T_Align16 > FixedSizeAllocatorWithCleanup< T, S, A, T_Align16 > FixedSizeAllocatorWithCleanup< T, S, A, false > FixedSizeAllocatorWithCleanup< T, S, A, true > NullAllocator< T >

Public Types

typedef T value_type
 
typedef size_t size_type
 
typedef std::ptrdiff_t difference_type
 
typedef T * pointer
 
typedef const T * const_pointer
 
typedef T & reference
 
typedef const T & const_reference
 

Public Member Functions

pointer address (reference r) const
 
const_pointer address (const_reference r) const
 
void construct (pointer p, const T &val)
 
void destroy (pointer p)
 
CRYPTOPP_CONSTEXPR size_type max_size () const
 Returns the maximum number of elements the allocator can provide.
 

Static Public Attributes

static const size_type ELEMS_MAX = SIZE_MAX/sizeof(T)
 Returns the maximum number of elements the allocator can provide.
 

Static Protected Member Functions

static void CheckSize (size_t size)
 Verifies the allocator can satisfy a request based on size.
 

Detailed Description

template<class T>
class AllocatorBase< T >

Base class for all allocators used by SecBlock.

Template Parameters
Tthe class or type

Definition at line 29 of file secblock.h.

Member Typedef Documentation

◆ const_pointer

template<class T >
typedef const T* AllocatorBase< T >::const_pointer

Definition at line 36 of file secblock.h.

◆ const_reference

template<class T >
typedef const T& AllocatorBase< T >::const_reference

Definition at line 38 of file secblock.h.

◆ difference_type

template<class T >
typedef std::ptrdiff_t AllocatorBase< T >::difference_type

Definition at line 34 of file secblock.h.

◆ pointer

template<class T >
typedef T* AllocatorBase< T >::pointer

Definition at line 35 of file secblock.h.

◆ reference

template<class T >
typedef T& AllocatorBase< T >::reference

Definition at line 37 of file secblock.h.

◆ size_type

template<class T >
typedef size_t AllocatorBase< T >::size_type

Definition at line 33 of file secblock.h.

◆ value_type

template<class T >
typedef T AllocatorBase< T >::value_type

Definition at line 32 of file secblock.h.

Member Function Documentation

◆ address() [1/2]

template<class T >
const_pointer AllocatorBase< T >::address ( const_reference  r) const
inline

Definition at line 41 of file secblock.h.

◆ address() [2/2]

template<class T >
pointer AllocatorBase< T >::address ( reference  r) const
inline

Definition at line 40 of file secblock.h.

◆ CheckSize()

template<class T >
static void AllocatorBase< T >::CheckSize ( size_t  size)
inlinestaticprotected

Verifies the allocator can satisfy a request based on size.

Parameters
sizethe size of the allocation, in elements
Exceptions
InvalidArgument

CheckSize verifies the number of elements requested is valid.

If size is greater than max_size(), then InvalidArgument is thrown. The library throws InvalidArgument if the size is too large to satisfy.

Internally, preprocessor macros are used rather than std::numeric_limits because the latter is not a constexpr. Some compilers, like Clang, do not optimize it well under all circumstances. Compilers like GCC, ICC and MSVC appear to optimize it well in either form.

The sizeof(T) != 1 in the condition attempts to help the compiler optimize the check for byte types. Coverity findings for CONSTANT_EXPRESSION_RESULT were generated without it. For byte types, size never exceeded ELEMS_MAX but the code was not removed.

Note
size is the count of elements, and not the number of bytes

Definition at line 119 of file secblock.h.

◆ construct()

template<class T >
void AllocatorBase< T >::construct ( pointer  p,
const T &  val 
)
inline

Definition at line 42 of file secblock.h.

◆ destroy()

template<class T >
void AllocatorBase< T >::destroy ( pointer  p)
inline

Definition at line 43 of file secblock.h.

◆ max_size()

template<class T >
CRYPTOPP_CONSTEXPR size_type AllocatorBase< T >::max_size ( ) const
inline

Returns the maximum number of elements the allocator can provide.

Returns
the maximum number of elements the allocator can provide

Internally, preprocessor macros are used rather than std::numeric_limits because the latter is not a constexpr. Some compilers, like Clang, do not optimize it well under all circumstances. Compilers like GCC, ICC and MSVC appear to optimize it well in either form.

Definition at line 73 of file secblock.h.

Member Data Documentation

◆ ELEMS_MAX

template<class T >
const size_type AllocatorBase< T >::ELEMS_MAX = SIZE_MAX/sizeof(T)
static

Returns the maximum number of elements the allocator can provide.

ELEMS_MAX is the maximum number of elements the Allocator can provide. The value of ELEMS_MAX is SIZE_MAX/sizeof(T). std::numeric_limits was avoided due to lack of constexpr-ness in C++03 and below.

Note
In C++03 and below ELEMS_MAX is a static data member of type size_type. In C++11 and above ELEMS_MAX is an enum inheriting from size_type. In both cases ELEMS_MAX can be used before objects are fully constructed, and it does not suffer the limitations of class methods like max_size.
See also
Issue 346/CVE-2016-9939
Since
Crypto++ 6.0

Definition at line 64 of file secblock.h.


The documentation for this class was generated from the following file: