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
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
3 *
4 * libcbor is free software; you can redistribute it and/or modify
5 * it under the terms of the MIT license. See LICENSE for details.
6 */
7
8#ifndef LIBCBOR_MEMORY_UTILS_H
9#define LIBCBOR_MEMORY_UTILS_H
10
11#include <stdbool.h>
12#include <string.h>
13
14#include "cbor/common.h"
15
18bool _cbor_safe_to_multiply(size_t a, size_t b);
19
22bool _cbor_safe_to_add(size_t a, size_t b);
23
26size_t _cbor_safe_signaling_add(size_t a, size_t b);
27
35void* _cbor_alloc_multiple(size_t item_size, size_t item_count);
36
47void* _cbor_realloc_multiple(void* pointer, size_t item_size,
48 size_t item_count);
49
50#endif // LIBCBOR_MEMORY_UTILS_H
#define _CBOR_NODISCARD
Definition common.h:93
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_realloc_multiple(void *pointer, size_t item_size, size_t item_count)
Overflow-proof contiguous array reallocation.
void * _cbor_alloc_multiple(size_t item_size, size_t item_count)
Overflow-proof contiguous array allocation.
bool _cbor_safe_to_multiply(size_t a, size_t b)
Can a and b be multiplied without overflowing size_t?