summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian <brian@yutani.localnet.net>2007-03-13 11:00:21 -0600
committerBrian <brian@yutani.localnet.net>2007-03-13 11:00:21 -0600
commitd8070889d73479d9dbef27ccf1ed5d26fc8760e5 (patch)
treeb33526ef17e7e5535911d6f93a74de8641e32ff6
parentc000843a14e73d593d87ff6674d0295d2cb64a12 (diff)
alloc an extra byte in _mesa_ShaderSourceARB() to silence a valgrind warning
-rw-r--r--src/mesa/main/shaders.c13
1 files 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);