diff --git a/helpers/glsize.hpp b/helpers/glsize.hpp index 9d7efbe..d9c42cf 100644 --- a/helpers/glsize.hpp +++ b/helpers/glsize.hpp @@ -494,10 +494,27 @@ _glDrawElementsBaseVertex_count(GLsizei count, GLenum type, const GLvoid *indice return maxindex + 1; } -#define _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, basevertex) _glDrawElementsBaseVertex_count(count, type, indices, basevertex) +static inline GLuint +_glDrawRangeElements_count_helper(GLuint end, GLsizei count, GLenum type, const GLvoid *indices, GLint basevertex) +{ + GLuint range_count = end + basevertex + 1; + GLuint index_count = _glDrawElementsBaseVertex_count(count, type, indices, basevertex); + const GLuint huge_value = 2 * 1000 * 1000 * 1000; + if (end > huge_value || basevertex > huge_value - end) { + os::log("apitrace: warning: DrawRangeElements uses implausibly large range (end = %u, basevertex = %d)\n", end, basevertex); + return index_count; + } + if (index_count > range_count) { + os::log("apitrace: warning: DrawRangeElements uses indices beyond the end of the given range\n"); + return index_count; + } + return range_count; +} + +#define _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, basevertex) _glDrawRangeElements_count_helper(end, count, type, indices, basevertex) -#define _glDrawElements_count(count, type, indices) _glDrawElementsBaseVertex_count(count, type, indices, 0); -#define _glDrawRangeElements_count(start, end, count, type, indices) _glDrawElements_count(count, type, indices) +#define _glDrawElements_count(count, type, indices) _glDrawElementsBaseVertex_count(count, type, indices, 0) +#define _glDrawRangeElements_count(start, end, count, type, indices) _glDrawRangeElementsBaseVertex_count(start, end, count, type, indices, 0) #define _glDrawRangeElementsEXT_count _glDrawRangeElements_count /* FIXME take in consideration instancing */