[Piglit] [PATCH] GL_ARB_ubo/maxblocks: fix writing to zero-length string

Brian Paul brianp at vmware.com
Thu Aug 2 09:04:39 PDT 2012


When get_shader() was called with blocks=0 we were allocating string
buffers of length zero.  Assigning prefix[0] = 0 caused an invalid
memory write (found w/ valgrind).  Adding one to the calloc() length
fixes this.

But compiling a shader string of length=0 seems a little strange...
---
 tests/spec/arb_uniform_buffer_object/maxblocks.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/spec/arb_uniform_buffer_object/maxblocks.c b/tests/spec/arb_uniform_buffer_object/maxblocks.c
index 6f67b59..b28cc2d 100644
--- a/tests/spec/arb_uniform_buffer_object/maxblocks.c
+++ b/tests/spec/arb_uniform_buffer_object/maxblocks.c
@@ -87,9 +87,9 @@ get_shader(GLenum target, const char *block_prefix, int blocks)
 	int i;
 
 	prefix = calloc(1, (strlen(block_prefix) * 2 + strlen(prefix_template) +
-			    20) * blocks);
+			    20) * blocks + 1);
 	body = calloc(1, (strlen(block_prefix) + strlen(body_template) +
-			  20) * blocks);
+			  20) * blocks + 1);
 	prefix_tail = prefix;
 	prefix[0] = 0;
 	body_tail = body;
-- 
1.7.3.4



More information about the Piglit mailing list