mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-04-19 22:10:19 +02:00
Support reallocarray(3)
This commit is contained in:
parent
1d7fc7ffe0
commit
98298a276b
2 changed files with 13 additions and 0 deletions
11
h_malloc.c
11
h_malloc.c
|
@ -1656,6 +1656,17 @@ EXPORT void *h_realloc(void *old, size_t size) {
|
||||||
return new;
|
return new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EXPORT void *h_reallocarray(void *ptr, size_t nmemb, size_t size) {
|
||||||
|
size_t bytes;
|
||||||
|
|
||||||
|
if (unlikely(__builtin_mul_overflow(nmemb, size, &bytes))) {
|
||||||
|
errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return h_realloc(ptr, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
EXPORT int h_posix_memalign(void **memptr, size_t alignment, size_t size) {
|
EXPORT int h_posix_memalign(void **memptr, size_t alignment, size_t size) {
|
||||||
return alloc_aligned(memptr, alignment, size, sizeof(void *));
|
return alloc_aligned(memptr, alignment, size, sizeof(void *));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ extern "C" {
|
||||||
#define h_malloc malloc
|
#define h_malloc malloc
|
||||||
#define h_calloc calloc
|
#define h_calloc calloc
|
||||||
#define h_realloc realloc
|
#define h_realloc realloc
|
||||||
|
#define h_reallocarray reallocarray
|
||||||
#define h_aligned_alloc aligned_alloc
|
#define h_aligned_alloc aligned_alloc
|
||||||
#define h_free free
|
#define h_free free
|
||||||
|
|
||||||
|
@ -51,6 +52,7 @@ extern "C" {
|
||||||
__attribute__((malloc)) __attribute__((alloc_size(1))) void *h_malloc(size_t size);
|
__attribute__((malloc)) __attribute__((alloc_size(1))) void *h_malloc(size_t size);
|
||||||
__attribute__((malloc)) __attribute__((alloc_size(1, 2))) void *h_calloc(size_t nmemb, size_t size);
|
__attribute__((malloc)) __attribute__((alloc_size(1, 2))) void *h_calloc(size_t nmemb, size_t size);
|
||||||
__attribute__((alloc_size(2))) void *h_realloc(void *ptr, size_t size);
|
__attribute__((alloc_size(2))) void *h_realloc(void *ptr, size_t size);
|
||||||
|
__attribute__((alloc_size(2, 3))) void *h_reallocarray(void *ptr, size_t nmemb, size_t size);
|
||||||
__attribute__((malloc)) __attribute__((alloc_size(2))) __attribute__((alloc_align(1)))
|
__attribute__((malloc)) __attribute__((alloc_size(2))) __attribute__((alloc_align(1)))
|
||||||
void *h_aligned_alloc(size_t alignment, size_t size);
|
void *h_aligned_alloc(size_t alignment, size_t size);
|
||||||
void h_free(void *ptr);
|
void h_free(void *ptr);
|
||||||
|
|
Loading…
Add table
Reference in a new issue