29#include <mstdlib/base/m_defs.h>
30#include <mstdlib/base/m_fmt.h>
31#include <mstdlib/base/m_str.h>
32#include <mstdlib/base/m_types.h>
38M_BEGIN_IGNORE_REDECLARATIONS
39#if M_BLACKLIST_FUNC == 1
40# define WARNING_MALLOC "Memory obtained by malloc can contain sensitive information, if not properly cleared when released, the memory could be obtained by another process or leaked by an incorrect program. use M_malloc/M_calloc,M_free/M_realloc instead."
44 M_DEPRECATED_MSG(WARNING_MALLOC,
void *malloc(
size_t))
49 M_DEPRECATED_MSG(WARNING_MALLOC,
void free(
void *))
54 M_DEPRECATED_MSG(WARNING_MALLOC,
void *calloc(
size_t,
size_t))
59 M_DEPRECATED_MSG(WARNING_MALLOC,
void *realloc(
void *,
size_t))
64 M_DEPRECATED_MSG(
"memcmp is vulnerable to timing attacks. use M_mem_eq",
int memcmp(
const void *,
const void *,
size_t))
67M_END_IGNORE_REDECLARATIONS
256M_API
void *
M_malloc(
size_t size) M_ALLOC_SIZE(1) M_WARN_UNUSED_RESULT M_MALLOC;
270M_API
void *
M_malloc_zero(
size_t size) M_ALLOC_SIZE(1) M_WARN_UNUSED_RESULT M_MALLOC;
302M_API
void *
M_realloc(
void *ptr,
size_t size) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT;
318M_API
void *
M_realloc_zero(
void *ptr,
size_t size) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT;
333M_API
void *
M_memdup(const
void *src,
size_t size) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_WARN_NONNULL(1) M_MALLOC;
353M_API
void *
M_memdup_max(const
void *src,
size_t size,
size_t min_alloc_size) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_WARN_NONNULL(1) M_MALLOC;
379M_API
void *
M_mem_move(
void *dst, const
void *src,
size_t size) M_WARN_NONNULL(1) M_WARN_NONNULL(2);
392M_API
void *
M_mem_copy(
void *dst, const
void *src,
size_t size) M_WARN_NONNULL(1) M_WARN_NONNULL(2);
405M_API M_bool
M_mem_eq(const
void *m1, const
void *m2,
size_t size) M_WARN_NONNULL(1) M_WARN_NONNULL(2);
421M_API
int M_mem_cmpsort(const
void *m1,
size_t size1, const
void *m2,
size_t size2) M_WARN_UNUSED_RESULT;
434M_API
void *
M_mem_chr(const
void *s, M_uint8 b,
size_t n) M_WARN_UNUSED_RESULT M_WARN_NONNULL(1);
446M_API M_bool
M_mem_contains(const
void *haystack,
size_t haystack_len, const
void *needle,
size_t needle_len) M_WARN_UNUSED_RESULT M_WARN_NONNULL(1) M_WARN_NONNULL(3);
459M_API
void *
M_mem_mem(const
void *haystack,
size_t haystack_len, const
void *needle,
size_t needle_len) M_WARN_UNUSED_RESULT M_WARN_NONNULL(1) M_WARN_NONNULL(3);
472M_API
void *
M_mem_rmem(const
void *haystack,
size_t haystack_len, const
void *needle,
size_t needle_len) M_WARN_UNUSED_RESULT M_WARN_NONNULL(1) M_WARN_NONNULL(3);
483M_API
void *
M_mem_str(const
void *haystack,
size_t haystack_len, const
char *needle) M_WARN_UNUSED_RESULT M_WARN_NONNULL(1);
484#define M_mem_str(haystack,haystack_len,needle) \
485 M_mem_mem(haystack,haystack_len,needle,M_str_len(needle) )
498M_API M_bool
M_mem_mempos(
const void *haystack,
size_t haystack_len,
const void *needle,
size_t needle_len,
size_t *idx) M_WARN_UNUSED_RESULT M_WARN_NONNULL(1) M_WARN_NONNULL(3);
499#define M_mem_strpos(haystack,haystack_len,needle,idx) \
500 M_mem_mempos(haystack,haystack_len,needle,M_str_len(needle) ,idx)
509M_API
size_t M_mem_count(
const void *s,
size_t s_len, M_uint8 b) M_WARN_UNUSED_RESULT M_WARN_NONNULL(1);
void * M_mem_chr(const void *s, M_uint8 b, size_t n) M_WARN_UNUSED_RESULT
M_bool M_malloc_deregister_errorcb(M_malloc_error_cb cb)
int M_mem_cmpsort(const void *m1, size_t size1, const void *m2, size_t size2) M_WARN_UNUSED_RESULT
void * M_realloc_zero(void *ptr, size_t size) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT
M_bool M_mem_contains(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) M_WARN_UNUSED_RESULT
void * M_memdup_max(const void *src, size_t size, size_t min_alloc_size) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_MALLOC
#define M_mem_str(haystack, haystack_len, needle)
Definition: m_mem.h:484
M_uint16 M_mem_calc_crc16_ccitt(const void *s, size_t s_len)
void * M_malloc_zero(size_t size) M_ALLOC_SIZE(1) M_WARN_UNUSED_RESULT M_MALLOC
M_uint8 M_mem_calc_crc8_ccitt(const void *s, size_t s_len)
void * M_mem_copy(void *dst, const void *src, size_t size)
void * M_mem_move(void *dst, const void *src, size_t size)
void * M_memdup(const void *src, size_t size) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT M_MALLOC
void * M_mem_mem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) M_WARN_UNUSED_RESULT
size_t M_mem_count(const void *s, size_t s_len, M_uint8 b) M_WARN_UNUSED_RESULT
M_bool M_mem_swap_bytes(M_uint8 *s, size_t s_len, size_t idx1, size_t idx2)
unsigned char M_mem_calc_lrc(const void *s, size_t s_len)
M_bool M_mem_eq(const void *m1, const void *m2, size_t size)
M_uint32 M_mem_calc_crc32(const void *s, size_t s_len)
void * M_mem_rmem(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len) M_WARN_UNUSED_RESULT
M_bool M_mem_mempos(const void *haystack, size_t haystack_len, const void *needle, size_t needle_len, size_t *idx) M_WARN_UNUSED_RESULT
void M_free(void *ptr) M_FREE(1)
void * M_mem_set(void *s, int c, size_t n)
void M_malloc_clear_errorcb(void)
void * M_malloc(size_t size) M_ALLOC_SIZE(1) M_WARN_UNUSED_RESULT M_MALLOC
M_bool(* M_malloc_error_cb)(void)
Definition: m_mem.h:206
M_bool M_malloc_register_errorcb(M_malloc_error_cb cb)
void * M_realloc(void *ptr, size_t size) M_ALLOC_SIZE(2) M_WARN_UNUSED_RESULT