Coverage Report

Created: 2025-07-11 06:49

/src/avahi/avahi-common/malloc.h
Line
Count
Source
1
#ifndef foomallochfoo
2
#define foomallochfoo
3
4
/***
5
  This file is part of avahi.
6
7
  avahi is free software; you can redistribute it and/or modify it
8
  under the terms of the GNU Lesser General Public License as
9
  published by the Free Software Foundation; either version 2.1 of the
10
  License, or (at your option) any later version.
11
12
  avahi is distributed in the hope that it will be useful, but WITHOUT
13
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14
  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15
  Public License for more details.
16
17
  You should have received a copy of the GNU Lesser General Public
18
  License along with avahi; if not, write to the Free Software
19
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20
  USA.
21
***/
22
23
/** \file malloc.h Memory allocation */
24
25
#include <sys/types.h>
26
#include <stdarg.h>
27
#include <limits.h>
28
#include <assert.h>
29
30
#include <avahi-common/cdecl.h>
31
#include <avahi-common/gccmacro.h>
32
33
AVAHI_C_DECL_BEGIN
34
35
/** Allocate some memory, just like the libc malloc() */
36
void *avahi_malloc(size_t size) AVAHI_GCC_ALLOC_SIZE(1);
37
38
/** Similar to avahi_malloc() but set the memory to zero */
39
void *avahi_malloc0(size_t size) AVAHI_GCC_ALLOC_SIZE(1);
40
41
/** Free some memory */
42
void avahi_free(void *p);
43
44
/** Similar to libc's realloc() */
45
void *avahi_realloc(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2);
46
47
/** Internal helper for avahi_new() */
48
241k
static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) {
49
241k
    assert(n < INT_MAX/k);
50
241k
    return avahi_malloc(n*k);
51
241k
}
Unexecuted instantiation: fuzz-domain.c:avahi_new_internal
malloc.c:avahi_new_internal
Line
Count
Source
48
5.43k
static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) {
49
5.43k
    assert(n < INT_MAX/k);
50
5.43k
    return avahi_malloc(n*k);
51
5.43k
}
Unexecuted instantiation: alternative.c:avahi_new_internal
Unexecuted instantiation: domain.c:avahi_new_internal
Unexecuted instantiation: address.c:avahi_new_internal
Unexecuted instantiation: fuzz-ini-file-parser.c:avahi_new_internal
ini-file-parser.c:avahi_new_internal
Line
Count
Source
48
3.49k
static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) {
49
3.49k
    assert(n < INT_MAX/k);
50
3.49k
    return avahi_malloc(n*k);
51
3.49k
}
Unexecuted instantiation: fuzz-consume-record.c:avahi_new_internal
Unexecuted instantiation: dns.c:avahi_new_internal
rr.c:avahi_new_internal
Line
Count
Source
48
184k
static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) {
49
184k
    assert(n < INT_MAX/k);
50
184k
    return avahi_malloc(n*k);
51
184k
}
hashmap.c:avahi_new_internal
Line
Count
Source
48
44.4k
static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) {
49
44.4k
    assert(n < INT_MAX/k);
50
44.4k
    return avahi_malloc(n*k);
51
44.4k
}
Unexecuted instantiation: domain-util.c:avahi_new_internal
Unexecuted instantiation: util.c:avahi_new_internal
strlst.c:avahi_new_internal
Line
Count
Source
48
3.59k
static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) {
49
3.59k
    assert(n < INT_MAX/k);
50
3.59k
    return avahi_malloc(n*k);
51
3.59k
}
Unexecuted instantiation: fuzz-consume-key.c:avahi_new_internal
Unexecuted instantiation: fuzz-packet.c:avahi_new_internal
Unexecuted instantiation: fuzz-strlst.c:avahi_new_internal
52
53
/** Allocate n new structures of the specified type. */
54
241k
#define avahi_new(type, n) ((type*) avahi_new_internal((n), sizeof(type)))
55
56
/** Internal helper for avahi_new0() */
57
2.33k
static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new0_internal(unsigned n, size_t k) {
58
2.33k
    assert(n < INT_MAX/k);
59
2.33k
    return avahi_malloc0(n*k);
60
2.33k
}
Unexecuted instantiation: fuzz-domain.c:avahi_new0_internal
Unexecuted instantiation: malloc.c:avahi_new0_internal
Unexecuted instantiation: alternative.c:avahi_new0_internal
Unexecuted instantiation: domain.c:avahi_new0_internal
Unexecuted instantiation: address.c:avahi_new0_internal
Unexecuted instantiation: fuzz-ini-file-parser.c:avahi_new0_internal
Unexecuted instantiation: ini-file-parser.c:avahi_new0_internal
Unexecuted instantiation: fuzz-consume-record.c:avahi_new0_internal
Unexecuted instantiation: dns.c:avahi_new0_internal
Unexecuted instantiation: rr.c:avahi_new0_internal
hashmap.c:avahi_new0_internal
Line
Count
Source
57
2.33k
static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new0_internal(unsigned n, size_t k) {
58
2.33k
    assert(n < INT_MAX/k);
59
2.33k
    return avahi_malloc0(n*k);
60
2.33k
}
Unexecuted instantiation: domain-util.c:avahi_new0_internal
Unexecuted instantiation: util.c:avahi_new0_internal
Unexecuted instantiation: strlst.c:avahi_new0_internal
Unexecuted instantiation: fuzz-consume-key.c:avahi_new0_internal
Unexecuted instantiation: fuzz-packet.c:avahi_new0_internal
Unexecuted instantiation: fuzz-strlst.c:avahi_new0_internal
61
62
/** Same as avahi_new() but set the memory to zero */
63
2.33k
#define avahi_new0(type, n) ((type*) avahi_new0_internal((n), sizeof(type)))
64
65
/** Just like libc's strdup() */
66
char *avahi_strdup(const char *s);
67
68
/** Just like libc's strndup() */
69
char *avahi_strndup(const char *s, size_t l);
70
71
/** Duplicate the given memory block into a new one allocated with avahi_malloc() */
72
void *avahi_memdup(const void *s, size_t l) AVAHI_GCC_ALLOC_SIZE(2);
73
74
/** Wraps allocator functions */
75
typedef struct AvahiAllocator {
76
    void* (*malloc)(size_t size) AVAHI_GCC_ALLOC_SIZE(1);
77
    void (*free)(void *p);
78
    void* (*realloc)(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2);
79
    void* (*calloc)(size_t nmemb, size_t size) AVAHI_GCC_ALLOC_SIZE2(1,2);   /**< May be NULL */
80
} AvahiAllocator;
81
82
/** Change the allocator. May be NULL to return to default (libc)
83
 * allocators. The structure is not copied! */
84
void avahi_set_allocator(const AvahiAllocator *a);
85
86
/** Like sprintf() but store the result in a freshly allocated buffer. Free this with avahi_free() */
87
char *avahi_strdup_printf(const char *fmt, ... ) AVAHI_GCC_PRINTF_ATTR12;
88
89
/** \cond fulldocs */
90
/** Same as avahi_strdup_printf() but take a va_list instead of varargs */
91
char *avahi_strdup_vprintf(const char *fmt, va_list ap);
92
/** \endcond */
93
94
AVAHI_C_DECL_END
95
96
#endif