dawn/native: Fix undefined behaviour in BindGroupTracker when passing no dynamic offsets

In [Mach engine](https://machengine.org), we compile Dawn's C++ sources using Zig as the C/C++
compiler and Zig's build system (we don't use Dawn's regular build system.) Zig uses clang
with UBSan enabled by default: this caught this instance of undefined behavior, where passing
no dynamic offsets would result in memcpy being called with size 0.

We've encountered at least [one other instance of undefined behavior](https://github.com/hexops/mach/issues/239)
via UBSan in addition to this one, which I will send another CL to fix soon. I'll also verify
we don't see any other instances of UB.

Bug: dawn:1371

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
Change-Id: Ifc3b938e990b6a0a3b203796ea99ee5abb9a4a09
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87380
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Stephen Gutekanst 2022-04-22 04:53:21 +00:00 committed by Dawn LUCI CQ
parent 81a3c7cbdf
commit c2f9fea56b
1 changed files with 3 additions and 1 deletions

View File

@ -133,7 +133,9 @@ namespace dawn::native {
static void SetDynamicOffsets(uint32_t* data,
uint32_t dynamicOffsetCount,
uint32_t* dynamicOffsets) {
memcpy(data, dynamicOffsets, sizeof(uint32_t) * dynamicOffsetCount);
if (dynamicOffsetCount > 0) {
memcpy(data, dynamicOffsets, sizeof(uint32_t) * dynamicOffsetCount);
}
}
};