Do not copy an empty run into an unallocated arena

memcpy() must not be passed a null pointer even for zero bytes, which
arena_run() did for an empty run while the arena was still empty
(ci_test_clang_sanitizer: "null pointer passed as argument 1" in
builder.hpp). Only the slow path can see such a run.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann committed 2026-10-17 23:07:04 +02:00
1 parent a43bad747a
commit badbe685a5
2 files changed
+6 -2

No files matched your search

+3 -1
View File
@@ -415,8 +415,10 @@ class builder
arena_ensure(16);
std::memcpy(m_arena_write, r, 16);
}
else
else if (n != 0)
{
// (an empty run leaves an empty arena unallocated, and memcpy()
// must not be passed its null pointer even for zero bytes)
arena_ensure(n);
std::memcpy(m_arena_write, r, n);
}
+3 -1
View File
@@ -1039,8 +1039,10 @@ class builder
arena_ensure(16);
std::memcpy(m_arena_write, r, 16);
}
else
else if (n != 0)
{
// (an empty run leaves an empty arena unallocated, and memcpy()
// must not be passed its null pointer even for zero bytes)
arena_ensure(n);
std::memcpy(m_arena_write, r, n);
}