From d8070889d73479d9dbef27ccf1ed5d26fc8760e5 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 13 Mar 2007 11:00:21 -0600 Subject: [PATCH] alloc an extra byte in _mesa_ShaderSourceARB() to silence a valgrind warning --- src/mesa/main/shaders.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c index 5bd4a3f5ff5..4c8ba47bcb3 100644 --- a/src/mesa/main/shaders.c +++ b/src/mesa/main/shaders.c @@ -373,7 +373,7 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count, { GET_CURRENT_CONTEXT(ctx); GLint *offsets; - GLsizei i; + GLsizei i, totalLength; GLcharARB *source; if (string == NULL) { @@ -406,8 +406,12 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count, offsets[i] += offsets[i - 1]; } - source = (GLcharARB *) _mesa_malloc((offsets[count - 1] + 1) * - sizeof(GLcharARB)); + /* Total length of source string is sum off all strings plus two. + * One extra byte for terminating zero, another extra byte to silence + * valgrind warnings in the parser/grammer code. + */ + totalLength = offsets[count - 1] + 2; + source = (GLcharARB *) _mesa_malloc(totalLength * sizeof(GLcharARB)); if (source == NULL) { _mesa_free((GLvoid *) offsets); _mesa_error(ctx, GL_OUT_OF_MEMORY, "glShaderSourceARB"); @@ -419,7 +423,8 @@ _mesa_ShaderSourceARB(GLhandleARB shaderObj, GLsizei count, _mesa_memcpy(source + start, string[i], (offsets[i] - start) * sizeof(GLcharARB)); } - source[offsets[count - 1]] = '\0'; + source[totalLength - 1] = '\0'; + source[totalLength - 2] = '\0'; ctx->Driver.ShaderSource(ctx, shaderObj, source); -- 2.30.2