From a42cba815ca34c28000670462c878d68ec89c746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 7 Feb 2016 18:44:51 -0800 Subject: [PATCH] Added checks for OOB transform cache access. --- src/bgfx_p.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 9e4e5a171..815529175 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -925,6 +925,10 @@ namespace bgfx float* toPtr(uint32_t _cacheIdx) { + BX_CHECK(_cacheIdx < BGFX_CONFIG_MAX_MATRIX_CACHE, "Matrix cache out of bounds index %d (max: %d)" + , _cacheIdx + , BGFX_CONFIG_MAX_MATRIX_CACHE + ); return m_cache[_cacheIdx].un.val; } @@ -1493,8 +1497,12 @@ namespace bgfx void setTransform(uint32_t _cache, uint16_t _num) { + BX_CHECK(_cache < BGFX_CONFIG_MAX_MATRIX_CACHE, "Matrix cache out of bounds index %d (max: %d)" + , _cache + , BGFX_CONFIG_MAX_MATRIX_CACHE + ); m_draw.m_matrix = _cache; - m_draw.m_num = _num; + m_draw.m_num = bx::uint32_min(_cache+_num, BGFX_CONFIG_MAX_MATRIX_CACHE-1) - _cache; } void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices)