X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/b0c2a4be2d1f4f93ab01d0858979a12ef0735ec1..80890b99fec2630ef0a1a0805d894c3d86c16506:/lunaix-os/kernel/mm/kalloc.c diff --git a/lunaix-os/kernel/mm/kalloc.c b/lunaix-os/kernel/mm/kalloc.c index 675a51f..e9f0564 100644 --- a/lunaix-os/kernel/mm/kalloc.c +++ b/lunaix-os/kernel/mm/kalloc.c @@ -14,16 +14,16 @@ #include #include -#include +#include #include -#include +#include #include extern uint8_t __kernel_heap_start; -heap_context_t __kalloc_kheap; +static heap_context_t __kalloc_kheap; void* lx_malloc_internal(heap_context_t* heap, size_t size); @@ -82,13 +82,20 @@ lxmalloc(size_t size) { } void* -lxcalloc(size_t size) { - void* ptr = lxmalloc(size); +lxcalloc(size_t n, size_t elem) { + size_t pd = n * elem; + + // overflow detection + if (pd < elem || pd < n) { + return NULL; + } + + void* ptr = lxmalloc(pd); if (!ptr) { return NULL; } - return memset(ptr, 0, size); + return memset(ptr, 0, pd); } void