{
GET_CURRENT_CONTEXT(ctx);
GLint *offsets;
- GLsizei i;
+ GLsizei i, totalLength;
GLcharARB *source;
if (string == NULL) {
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");
_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);