diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-01-27 16:50:57 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-27 16:50:57 -0500 |
| commit | 5c6ab6d5198ebff276da9cb8d3024802f22ba9f3 (patch) | |
| tree | 8e12a913d26100961b5bd20281cd0a33f143079c | |
| parent | a9e1beeb003644f4034b9485ad00e273ad52c9f1 (diff) | |
When using setUniform clamp the amount of data written to the buffer size. (#1181)
| -rw-r--r-- | tools/render-test/bind-location.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/render-test/bind-location.cpp b/tools/render-test/bind-location.cpp index 114ca7e8e..73b492938 100644 --- a/tools/render-test/bind-location.cpp +++ b/tools/render-test/bind-location.cpp @@ -700,6 +700,17 @@ SlangResult BindLocation::setUniform(const void* data, size_t sizeInBytes) const if (m_value && point) { size_t offset = point->m_offset; + ptrdiff_t maxSizeInBytes = m_value->m_sizeInBytes - offset; + SLANG_ASSERT(maxSizeInBytes > 0); + + if (maxSizeInBytes <= 0) + { + return SLANG_FAIL; + } + + // Clamp such that only fill in what's available to write + sizeInBytes = sizeInBytes > size_t(maxSizeInBytes) ? size_t(maxSizeInBytes) : sizeInBytes; + // Make sure it's in range SLANG_ASSERT(offset + sizeInBytes <= m_value->m_sizeInBytes); @@ -992,7 +1003,7 @@ SlangResult CPULikeBindRoot::setArrayCount(const BindLocation& location, int cou } const size_t maxElementCount = (value->m_sizeInBytes / elementStride); - if (count <= maxElementCount) + if (size_t(count) <= maxElementCount) { // Just initialize the space ::memset(value->m_data + elementStride * value->m_elementCount, 0, (count - value->m_elementCount) * elementStride); |
