MCPcopy Create free account
hub / github.com/apache/nuttx / calloc

Function calloc

mm/umm_heap/umm_calloc.c:49–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48#undef calloc
49FAR void *calloc(size_t n, size_t elem_size)
50{
51#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
52 /* Use zalloc() because it implements the sbrk() logic */
53
54 FAR void *mem = NULL;
55 /* Verify input parameters
56 *
57 * elem_size or n is zero treats as valid input.
58 *
59 * Assure that the following multiplication cannot overflow the size_t
60 * type, i.e., that: SIZE_MAX >= n * elem_size
61 *
62 * Refer to SEI CERT C Coding Standard.
63 */
64
65 if (elem_size == 0 || n <= (SIZE_MAX / elem_size))
66 {
67 /* Use zalloc() because it implements the sbrk() logic */
68
69 mem = zalloc(n * elem_size);
70 }
71
72 return mem;
73#else
74 /* Use mm_calloc() because it implements the clear */
75
76 FAR void *mem = mm_calloc(USR_HEAP, n, elem_size);
77
78 if (mem == NULL)
79 {
80 set_errno(ENOMEM);
81 }
82 else
83 {
84 mm_notify_pressure(mm_heapfree(USR_HEAP),
85 mm_heapfree_largest(USR_HEAP));
86 }
87
88 return mem;
89#endif
90}

Callers

nothing calls this directly

Calls 5

mm_notify_pressureFunction · 0.85
zallocFunction · 0.70
mm_callocFunction · 0.50
mm_heapfreeFunction · 0.50
mm_heapfree_largestFunction · 0.50

Tested by

no test coverage detected