mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
AK: Avoid UB in TypedTransfer
Don't be calling __builtin_memfoo() with null pointer arguments. Found by KUBSAN :^)
This commit is contained in:
parent
f4eb1f261f
commit
8e7ad28a33
Notes:
sideshowbarker
2024-07-18 22:34:43 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/8e7ad28a33d
1 changed files with 9 additions and 0 deletions
|
@ -35,6 +35,9 @@ class TypedTransfer {
|
|||
public:
|
||||
static size_t move(T* destination, T* source, size_t count)
|
||||
{
|
||||
if (!count)
|
||||
return 0;
|
||||
|
||||
if constexpr (Traits<T>::is_trivial()) {
|
||||
__builtin_memmove(destination, source, count * sizeof(T));
|
||||
return count;
|
||||
|
@ -52,6 +55,9 @@ public:
|
|||
|
||||
static size_t copy(T* destination, const T* source, size_t count)
|
||||
{
|
||||
if (!count)
|
||||
return 0;
|
||||
|
||||
if constexpr (Traits<T>::is_trivial()) {
|
||||
__builtin_memmove(destination, source, count * sizeof(T));
|
||||
return count;
|
||||
|
@ -69,6 +75,9 @@ public:
|
|||
|
||||
static bool compare(const T* a, const T* b, size_t count)
|
||||
{
|
||||
if (!count)
|
||||
return true;
|
||||
|
||||
if constexpr (Traits<T>::is_trivial())
|
||||
return !__builtin_memcmp(a, b, count * sizeof(T));
|
||||
|
||||
|
|
Loading…
Reference in a new issue