10#include "src/lib/log.h"
14char *
my_strdup(
const char *str,
size_t len);
21__attribute__((malloc))
22static inline void *malloc_assert(
size_t size) {
24 MYMPD_LOG_EMERG(NULL,
"Allocation zero bytes it not allowed");
27 void *p = malloc(size);
29 MYMPD_LOG_EMERG(NULL,
"Failure allocating %lu bytes of memory", (
unsigned long) size);
41__attribute__((malloc))
42static inline void *malloc_assert_count(
size_t count,
size_t size) {
46 MYMPD_LOG_EMERG(NULL,
"Allocation zero bytes it not allowed");
49 if (size > SIZE_MAX / count) {
50 MYMPD_LOG_EMERG(NULL,
"Overflow in allocating call for %lu x %lu", (
unsigned long) count, (
unsigned long) size);
53 void *p = malloc(count * size);
55 MYMPD_LOG_EMERG(NULL,
"Failure allocating %lu bytes of memory", (
unsigned long) (count * size));
67__attribute__((malloc))
68static inline void *calloc_assert(
size_t count,
size_t size) {
72 MYMPD_LOG_EMERG(NULL,
"Allocation zero bytes it not allowed");
75 if (size > SIZE_MAX / count) {
76 MYMPD_LOG_EMERG(NULL,
"Overflow in allocating call for %lu x %lu", (
unsigned long) count, (
unsigned long) size);
79 void *p = calloc(count, size);
81 MYMPD_LOG_EMERG(NULL,
"Failure allocating %lu bytes of memory", (
unsigned long) (count * size));
93__attribute__((malloc))
94static inline void *realloc_assert(
void *ptr,
size_t size) {
96 MYMPD_LOG_EMERG(NULL,
"Allocation zero bytes it not allowed");
99 void *p = realloc(ptr, size);
101 MYMPD_LOG_EMERG(NULL,
"Failure allocating %lu bytes of memory", (
unsigned long) size);
114__attribute__((malloc))
115static inline void *realloc_assert_count(
void *ptr,
size_t count,
size_t size) {
119 MYMPD_LOG_EMERG(NULL,
"Allocation zero bytes it not allowed");
122 if (size > SIZE_MAX / count) {
123 MYMPD_LOG_EMERG(NULL,
"Overflow in re-allocating call for %lu x %lu", (
unsigned long) count, (
unsigned long) size);
126 void *p = realloc(ptr, count * size);
128 MYMPD_LOG_EMERG(NULL,
"Failure allocating %lu bytes of memory", (
unsigned long) (count * size));
138#define FREE_PTR(PTR) do { \
char * my_strdup(const char *str, size_t len)
Definition mem.c:22