libcbor 0.12.0
libcbor is a C library for parsing and generating CBOR, the general-purpose schema-less binary data format.
Loading...
Searching...
No Matches
memory_utils.h File Reference
#include <stdbool.h>
#include <string.h>
#include "cbor/common.h"

Go to the source code of this file.

Functions

bool _cbor_safe_to_multiply (size_t a, size_t b)
 Can a and b be multiplied without overflowing size_t?
 
bool _cbor_safe_to_add (size_t a, size_t b)
 Can a and b be added without overflowing size_t?
 
size_t _cbor_safe_signaling_add (size_t a, size_t b)
 Adds a and b, propagating zeros and returning 0 on overflow.
 
void * _cbor_alloc_multiple (size_t item_size, size_t item_count)
 Overflow-proof contiguous array allocation.
 
void * _cbor_realloc_multiple (void *pointer, size_t item_size, size_t item_count)
 Overflow-proof contiguous array reallocation.
 

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 42 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 50 of file memory_utils.c.

◆ _cbor_safe_signaling_add()

size_t _cbor_safe_signaling_add ( size_t a,
size_t b )

Adds a and b, propagating zeros and returning 0 on overflow.

Definition at line 36 of file memory_utils.c.

◆ _cbor_safe_to_add()

bool _cbor_safe_to_add ( size_t a,
size_t b )

Can a and b be added without overflowing size_t?

Definition at line 30 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.