Skip to content

Commit 5c6ab6d

Browse files
authored
When using setUniform clamp the amount of data written to the buffer size. (shader-slang#1181)
1 parent a9e1bee commit 5c6ab6d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tools/render-test/bind-location.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,17 @@ SlangResult BindLocation::setUniform(const void* data, size_t sizeInBytes) const
700700
if (m_value && point)
701701
{
702702
size_t offset = point->m_offset;
703+
ptrdiff_t maxSizeInBytes = m_value->m_sizeInBytes - offset;
704+
SLANG_ASSERT(maxSizeInBytes > 0);
705+
706+
if (maxSizeInBytes <= 0)
707+
{
708+
return SLANG_FAIL;
709+
}
710+
711+
// Clamp such that only fill in what's available to write
712+
sizeInBytes = sizeInBytes > size_t(maxSizeInBytes) ? size_t(maxSizeInBytes) : sizeInBytes;
713+
703714
// Make sure it's in range
704715
SLANG_ASSERT(offset + sizeInBytes <= m_value->m_sizeInBytes);
705716

@@ -992,7 +1003,7 @@ SlangResult CPULikeBindRoot::setArrayCount(const BindLocation& location, int cou
9921003
}
9931004

9941005
const size_t maxElementCount = (value->m_sizeInBytes / elementStride);
995-
if (count <= maxElementCount)
1006+
if (size_t(count) <= maxElementCount)
9961007
{
9971008
// Just initialize the space
9981009
::memset(value->m_data + elementStride * value->m_elementCount, 0, (count - value->m_elementCount) * elementStride);

0 commit comments

Comments
 (0)