Compare commits
No commits in common. "26b44e651dedc2868027dcdc3ccf60f8ffbe0c25" and "8ff9cb4b96c682650212c2bfe664e1f89b4525cc" have entirely different histories.
26b44e651d
...
8ff9cb4b96
@ -5,7 +5,6 @@
|
||||
#include "memory/KernelVM.h"
|
||||
#include "memory/MemoryManager.h"
|
||||
#include <luna/Alignment.h>
|
||||
#include <luna/SafeArithmetic.h>
|
||||
#include <luna/String.h>
|
||||
#include <luna/SystemError.h>
|
||||
|
||||
@ -333,7 +332,8 @@ Result<void*> krealloc(void* ptr, usize size)
|
||||
|
||||
Result<void*> kcalloc(usize nmemb, usize size)
|
||||
{
|
||||
const usize realsize = TRY(safe_mul(nmemb, size));
|
||||
// FIXME: Check for overflows.
|
||||
const usize realsize = nmemb * size;
|
||||
void* const ptr = TRY(kmalloc(realsize));
|
||||
return memset(ptr, 0, realsize);
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
#include <luna/Result.h>
|
||||
|
||||
template <typename T> constexpr bool add_will_overflow(T a, T b)
|
||||
{
|
||||
return __builtin_add_overflow_p(a, b, (T)0);
|
||||
}
|
||||
|
||||
template <typename T> constexpr bool sub_will_overflow(T a, T b)
|
||||
{
|
||||
return __builtin_sub_overflow_p(a, b, (T)0);
|
||||
}
|
||||
|
||||
template <typename T> constexpr bool mul_will_overflow(T a, T b)
|
||||
{
|
||||
return __builtin_mul_overflow_p(a, b, (T)0);
|
||||
}
|
||||
|
||||
template <typename T> Result<T> safe_add(T a, T b)
|
||||
{
|
||||
T result;
|
||||
|
||||
if (__builtin_add_overflow(a, b, &result)) return err(EOVERFLOW);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T> Result<T> safe_sub(T a, T b)
|
||||
{
|
||||
T result;
|
||||
|
||||
if (__builtin_sub_overflow(a, b, &result)) return err(EOVERFLOW);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T> Result<T> safe_mul(T a, T b)
|
||||
{
|
||||
T result;
|
||||
|
||||
if (__builtin_mul_overflow(a, b, &result)) return err(EOVERFLOW);
|
||||
|
||||
return result;
|
||||
}
|
Loading…
Reference in New Issue
Block a user