Heap: Use safe_mul in kcalloc()
This commit is contained in:
parent
e91c04b1d1
commit
b338126854
@ -5,6 +5,7 @@
|
|||||||
#include "memory/KernelVM.h"
|
#include "memory/KernelVM.h"
|
||||||
#include "memory/MemoryManager.h"
|
#include "memory/MemoryManager.h"
|
||||||
#include <luna/Alignment.h>
|
#include <luna/Alignment.h>
|
||||||
|
#include <luna/SafeArithmetic.h>
|
||||||
#include <luna/String.h>
|
#include <luna/String.h>
|
||||||
#include <luna/SystemError.h>
|
#include <luna/SystemError.h>
|
||||||
|
|
||||||
@ -332,8 +333,7 @@ Result<void*> krealloc(void* ptr, usize size)
|
|||||||
|
|
||||||
Result<void*> kcalloc(usize nmemb, usize size)
|
Result<void*> kcalloc(usize nmemb, usize size)
|
||||||
{
|
{
|
||||||
// FIXME: Check for overflows.
|
const usize realsize = TRY(safe_mul(nmemb, size));
|
||||||
const usize realsize = nmemb * size;
|
|
||||||
void* const ptr = TRY(kmalloc(realsize));
|
void* const ptr = TRY(kmalloc(realsize));
|
||||||
return memset(ptr, 0, realsize);
|
return memset(ptr, 0, realsize);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user