From de2944ba73141f1ebdef0c7e6f83c2c40b85f547 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Tue, 22 Oct 2019 20:05:14 -0700 Subject: Added validation and correction of IShaderVariable::SetArray arguments --- .../GraphicsEngine/include/ShaderResourceVariableBase.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.h b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.h index 2501bd86..5227f84a 100644 --- a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.h +++ b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.h @@ -306,6 +306,22 @@ bool VerifyResourceViewBinding(const ResourceAttribsType& Attribs, return BindingOK; } +inline void VerifyAndCorrectSetArrayArguments(const char* Name, Uint32 ArraySize, Uint32& FirstElement, Uint32& NumElements) +{ + if (FirstElement >= ArraySize) + { + LOG_ERROR_MESSAGE("SetArray arguments are invalid for '", Name,"' variable: FirstElement (", FirstElement, ") is out of allowed range 0 .. ", ArraySize-1); + FirstElement = ArraySize-1; + NumElements = 0; + } + + if (FirstElement + NumElements > ArraySize) + { + LOG_ERROR_MESSAGE("SetArray arguments are invalid for '", Name,"' variable: specified element range (", FirstElement, " .. ", + FirstElement + NumElements-1, ") is out of array bounds 0 .. ", ArraySize-1); + NumElements = ArraySize - FirstElement; + } +} struct DefaultShaderVariableIDComparator { -- cgit v1.2.3