fix(shader): skip the push constant copy when there is nothing to copy

decodeResult and decodeAllocation called memcpy with the data() of
empty vectors, which may be null. Passing a null pointer to memcpy is
undefined even for a zero size, and UBSan reports it on every entry
without push constants, including the existing shader disk cache test.
The copy now runs only for a non-empty table, as Reader::Values does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01R5WJS4ZdQynAJesCZKH5hb
This commit is contained in:
Alberto Ruiz 2026-09-30 23:14:16 +02:00
parent bc51b337ad
commit cc3d2d21ef
1 changed files with 2 additions and 2 deletions

View File

@ -305,7 +305,7 @@ void decodeResult(Reader& reader, RecompileResult& result) {
std::vector<std::uint8_t> pushConstants;
reader.Values(pushConstants);
result.pushConstants.resize(pushConstants.size());
std::memcpy(result.pushConstants.data(), pushConstants.data(), pushConstants.size());
if (!pushConstants.empty()) std::memcpy(result.pushConstants.data(), pushConstants.data(), pushConstants.size());
reader.Value(result.bdaAbiVersion);
reader.Value(result.memoryOffsetDword);
reader.List(result.vertexAttributes, 28, [](Reader& in, VertexAttribute& attribute) {
@ -546,7 +546,7 @@ void decodeAllocation(Reader& reader, BindingAllocationResult& allocation) {
std::vector<std::uint8_t> pushConstants;
reader.Values(pushConstants);
allocation.pushConstants.resize(pushConstants.size());
std::memcpy(allocation.pushConstants.data(), pushConstants.data(), pushConstants.size());
if (!pushConstants.empty()) std::memcpy(allocation.pushConstants.data(), pushConstants.data(), pushConstants.size());
}
constexpr std::string_view NeutralSwitches[] = {