mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
AK: Correct ByteBuffer::{overwrite,slice*} bounds check
This commit is contained in:
parent
7f1d3f6d62
commit
cf5941c972
1 changed files with 11 additions and 11 deletions
|
@ -94,9 +94,9 @@ private:
|
||||||
Wrap,
|
Wrap,
|
||||||
Adopt
|
Adopt
|
||||||
};
|
};
|
||||||
explicit ByteBufferImpl(size_t); // For ConstructionMode=Uninitialized
|
explicit ByteBufferImpl(size_t); // For ConstructionMode=Uninitialized
|
||||||
ByteBufferImpl(const void*, size_t, ConstructionMode); // For ConstructionMode=Copy
|
ByteBufferImpl(const void*, size_t, ConstructionMode); // For ConstructionMode=Copy
|
||||||
ByteBufferImpl(void*, size_t, ConstructionMode); // For ConstructionMode=Wrap/Adopt
|
ByteBufferImpl(void*, size_t, ConstructionMode); // For ConstructionMode=Wrap/Adopt
|
||||||
ByteBufferImpl() {}
|
ByteBufferImpl() {}
|
||||||
|
|
||||||
u8* m_data { nullptr };
|
u8* m_data { nullptr };
|
||||||
|
@ -183,10 +183,10 @@ public:
|
||||||
{
|
{
|
||||||
if (is_null())
|
if (is_null())
|
||||||
return {};
|
return {};
|
||||||
if (offset >= this->size())
|
|
||||||
return {};
|
// I cannot hand you a slice I don't have
|
||||||
if (offset + size >= this->size())
|
ASSERT(offset + size <= this->size());
|
||||||
size = this->size() - offset;
|
|
||||||
return wrap(offset_pointer(offset), size);
|
return wrap(offset_pointer(offset), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,10 +194,10 @@ public:
|
||||||
{
|
{
|
||||||
if (is_null())
|
if (is_null())
|
||||||
return {};
|
return {};
|
||||||
if (offset >= this->size())
|
|
||||||
return {};
|
// I cannot hand you a slice I don't have
|
||||||
if (offset + size >= this->size())
|
ASSERT(offset + size <= this->size());
|
||||||
size = this->size() - offset;
|
|
||||||
return copy(offset_pointer(offset), size);
|
return copy(offset_pointer(offset), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ public:
|
||||||
void overwrite(size_t offset, const void* data, size_t data_size)
|
void overwrite(size_t offset, const void* data, size_t data_size)
|
||||||
{
|
{
|
||||||
// make sure we're not told to write past the end
|
// make sure we're not told to write past the end
|
||||||
ASSERT(offset + data_size < size());
|
ASSERT(offset + data_size <= size());
|
||||||
__builtin_memcpy(this->data() + offset, data, data_size);
|
__builtin_memcpy(this->data() + offset, data, data_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue