summaryrefslogtreecommitdiff
path: root/AK/ByteBuffer.h
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2022-05-07 17:41:26 +0200
committerAndreas Kling <kling@serenityos.org>2022-05-12 13:12:37 +0200
commit014b9fd709db11890e403617930646aed1270cb7 (patch)
tree6b129eb54aaf8f698a074f2f71c6e86e68083fb8 /AK/ByteBuffer.h
parentf40b6fbd0723e4c758d7e7f2fad048f7d89b3600 (diff)
downloadserenity-014b9fd709db11890e403617930646aed1270cb7.zip
AK+DHCPClient: Fix false positive gcc 12 warnings
The compiler would complain about `__builtin_memcpy` in ByteBuffer::copy writing out of bounds, as it isn't able to deduce the invariant that the inline buffer is only used when the requested size is smaller than the inline capacity. The other change is more bizarre. If the destructor's declaration exists, gcc complains about a `delete` operation causing an out-of-bounds array access. error: array subscript 'DHCPv4Client::__as_base [0]' is partly outside array bounds of 'unsigned char [8]' [-Werror=array-bounds] 14 | ~DHCPv4Client() = default; | ^ This looks like a compiler bug, and I'll report it if I find a suitable reduced reproducer.
Diffstat (limited to 'AK/ByteBuffer.h')
-rw-r--r--AK/ByteBuffer.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h
index d68a21b396..86274d5117 100644
--- a/AK/ByteBuffer.h
+++ b/AK/ByteBuffer.h
@@ -80,6 +80,8 @@ public:
[[nodiscard]] static ErrorOr<ByteBuffer> copy(void const* data, size_t size)
{
auto buffer = TRY(create_uninitialized(size));
+ if (buffer.m_inline && size > inline_capacity)
+ __builtin_unreachable();
if (size != 0)
__builtin_memcpy(buffer.data(), data, size);
return { move(buffer) };