From 33cabbfca6acb5149e26f87a538a7cb79f00cad2 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Tue, 10 Nov 2009 11:09:52 +0000 Subject: i915: Check for overflow before overflowing. As the immediate victim of the overflow would be to overwrite the maximum permissible value, the test was optimistic. Signed-off-by: Chris Wilson --- src/i915_3d.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/i915_3d.h b/src/i915_3d.h index 500817f4..f85780aa 100644 --- a/src/i915_3d.h +++ b/src/i915_3d.h @@ -420,8 +420,8 @@ do { \ */ #define FS_LOCALS(x) \ uint32_t _shader_buf[(x) * 3]; \ - int _max_shader_commands = x; \ - int _cur_shader_commands + unsigned int _max_shader_commands = x; \ + unsigned int _cur_shader_commands #define FS_BEGIN() \ do { \ @@ -430,12 +430,13 @@ do { \ #define FS_OUT(_shaderop) \ do { \ + if (_cur_shader_commands >= _max_shader_commands) \ + FatalError("fragment shader command buffer exceeded (%d)\n", \ + _cur_shader_commands); \ _shader_buf[_cur_shader_commands * 3 + 0] = _shaderop.ui[0]; \ _shader_buf[_cur_shader_commands * 3 + 1] = _shaderop.ui[1]; \ _shader_buf[_cur_shader_commands * 3 + 2] = _shaderop.ui[2]; \ - if (++_cur_shader_commands > _max_shader_commands) \ - FatalError("fragment shader command buffer exceeded (%d)\n", \ - _cur_shader_commands); \ + ++_cur_shader_commands; \ } while (0) #define FS_END() \ -- cgit v1.2.3