From d0d6fc911c43db48fb0c4332fd64ca3e80c4e3cd Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Tue, 25 Apr 2023 21:33:22 +0000 Subject: [PATCH] Return a pointer to a global static for zero-length GetMappedRange Bug: chromium:1430985 Change-Id: Iaca7a21487a5a7e2b41dd9a363a7efd913a0f208 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/129180 Kokoro: Kokoro Reviewed-by: Loko Kung Commit-Queue: Austin Eng Reviewed-by: Brendon Tiszka --- src/dawn/native/Buffer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp index 22fcffb05f..b2efa6208d 100644 --- a/src/dawn/native/Buffer.cpp +++ b/src/dawn/native/Buffer.cpp @@ -101,6 +101,9 @@ class ErrorBuffer final : public BufferBase { std::unique_ptr mFakeMappedData; }; +// GetMappedRange on a zero-sized buffer returns a pointer to this value. +static uint32_t sZeroSizedMappingData = 0xCAFED00D; + } // anonymous namespace MaybeError ValidateBufferDescriptor(DeviceBase* device, const BufferDescriptor* descriptor) { @@ -435,8 +438,7 @@ void* BufferBase::GetMappedRange(size_t offset, size_t size, bool writable) { return static_cast(mStagingBuffer->GetMappedPointer()) + offset; } if (mSize == 0) { - static uint32_t zeroRange = 0xCAFED00D; - return &zeroRange; + return &sZeroSizedMappingData; } uint8_t* start = static_cast(GetMappedPointer()); return start == nullptr ? nullptr : start + offset;