libcbor  0.5.0
libcbor is a C library for parsing and generating CBOR, the general-purpose schema-less binary data format.
Functions
memory_utils.c File Reference
#include "memory_utils.h"
#include "cbor/common.h"

Go to the source code of this file.

Functions

size_t _cbor_highest_bit (size_t number)
 Highest on bit position. More...
 
bool _cbor_safe_to_multiply (size_t a, size_t b)
 Can a and b be multiplied without overflowing size_t? More...
 
void * _cbor_alloc_multiple (size_t item_size, size_t item_count)
 Overflow-proof contiguous array allocation. More...
 
void * _cbor_realloc_multiple (void *pointer, size_t item_size, size_t item_count)
 Overflow-proof contiguous array reallocation. More...
 

Function Documentation

§ _cbor_alloc_multiple()

void* _cbor_alloc_multiple ( size_t  item_size,
size_t  item_count 
)

Overflow-proof contiguous array allocation.

Parameters
item_size
item_count
Returns
Region of item_size * item_count bytes, or NULL if the total size overflows size_t or the underlying allocator failed

Definition at line 30 of file memory_utils.c.

§ _cbor_highest_bit()

size_t _cbor_highest_bit ( size_t  number)

Highest on bit position.

Definition at line 14 of file memory_utils.c.

§ _cbor_realloc_multiple()

void* _cbor_realloc_multiple ( void *  pointer,
size_t  item_size,
size_t  item_count 
)

Overflow-proof contiguous array reallocation.

This implements the OpenBSD reallocarray functionality.

Parameters
pointer
item_size
item_count
Returns
Realloc'd of item_size * item_count bytes, or NULL if the total size overflows size_t or the underlying allocator failed

Definition at line 39 of file memory_utils.c.

§ _cbor_safe_to_multiply()

bool _cbor_safe_to_multiply ( size_t  a,
size_t  b 
)

Can a and b be multiplied without overflowing size_t?

Definition at line 25 of file memory_utils.c.