Add sc_allocarray() util

Add a function to allocate an array, which fails safely in the case
where the multiplication would overflow.
This commit is contained in:
Romain Vimont
2023-02-28 21:48:18 +01:00
parent c30bb893f8
commit cef9bf51a9
3 changed files with 27 additions and 0 deletions

12
app/src/util/memory.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef SC_MEMORY_H
#define SC_MEMORY_H
#include <stddef.h>
/* Like calloc(), but without initialization.
* Like reallocarray(), but without reallocation.
*/
void *
sc_allocarray(size_t nmemb, size_t size);
#endif